17.04.2014 Views

semaphores, classic problems

semaphores, classic problems

semaphores, classic problems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Bakery algorithm<br />

bool choosing[n]; // initially false<br />

int number[n]; // initially 0<br />

cobegin<br />

/* process i */<br />

while(true) {<br />

choosing[i] = true;<br />

number[i] = max(number[0], ..., number[n]) + 1;<br />

choosing[i] = false;<br />

for(j = 0; j != i; j++) {<br />

while(choosing[j]); // busy wait<br />

while(number[j] && number[j]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!