Checkpoint synchronization: Difference between revisions

m
Line 1,471:
 
=={{header|Oforth}}==
 
Checkpoint is implemented as a task. It :
 
- Receives n "jobDone" events from n tasks into a "jobs" channel.
 
- Then sends $allDone event to all tasks so they can work again.
 
Each task :
 
- Sleeps randomly between 1 and 1000 milliseconds, simulating its job.
 
- Then sends "jobDone" to the checkpoint using "jobs" channel.
 
- And waits for $allDone checkpoint return on its personal channel.
 
<lang Oforth>func: task(n, jobs, myChannel)
{
while(true) [
System.Out "TASK " << n << " : Beginning my work..." << cr
Line 1,494 ⟶ 1,487:
jobs send($jobDone) drop
myChannel receive drop
] ;
}
 
func: checkPoint(n, jobs, channels)
{
while(true) [
#[ jobs receive drop ] times(n)
"CHECKPOINT : All jobs done, sending done to all tasks" println
channels apply(#[ send($allDone) drop ])
] ;
}
 
func: testCheckPoint(n)
{
| jobs channels i |
n seq map(#[ drop Channel new]) ->channels
Line 1,513 ⟶ 1,502:
 
#[ checkPoint(n, jobs, channels) ] &
n loop: i [ #[ task(i, jobs, channels at(i)) ] & ] ;</lang>
}</lang>
 
=={{header|Perl}}==
1,015

edits