Checkpoint synchronization: Difference between revisions

m
m (→‎{{header|C++}}: fixed markup)
Line 2,145:
=={{header|Phix}}==
Simple multitasking solution: no locking required, no race condition possible, supports workers leaving and joining.
<lang Phix>-- demo\rosetta\checkpoint_synchronisation.exw
<lang Phix>constant NPARTS = 3
integer workers = 0
sequence waiters = {}
Line 2,151 ⟶ 2,152:
 
procedure checkpoint(integer task_id)
if length(waiters)+1=NPARTS or terminate then
printf(1,"checkpoint\n")
for i=1 to length(waiters) do
Line 2,188 ⟶ 2,189:
task_yield()
end while
printf(1,"escape keyed\n")
terminate = true
while workers>0 do
Line 2,262 ⟶ 2,264:
worker D completes part
checkpoint
escape keyed
worker C leaves
worker D leaves
7,796

edits