










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











try: mov
ll
sc
bnez R2,try beqz R3,try try: mov
ll
bnez R2,try sc
beqz R3,try
lock(counterlock); if(count==0) release=0; / First resets release / count++; / Count arrivals / unlock(counterlock); if(count==total){ / All arrived / count=0; / Reset counter / release = 1; / Release processes / }else { / Wait for more to come / spin(release==1); / Wait for release to be 1 / }
Problem: not really reusable - Two processes: fast and slow - Slow arrives first, reads release, sees 0 - Fast arrives, sets release to 1, goes on to execute other code, comes to barrier again, resets release, starts spinning - Slow now reads release again, sees 0 again - Now both processors are stuck and will never leave
localSense=!localSense; / Toggle local sense / lock(counterlock); count++; / Count arrivals / if(count==total){ / All arrived / count=0; / Reset counter / release=localSense; / Release processes / } unlock(counterlock); spin(release==localSense); / Wait to be released /
init: localSense = 0, release = 0
Proc 2 LD DLD F