













































































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!














































































Objectives
while (true) { /produce an item/ nextProduced = …. while (count == BUFFER_SIZE) ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; } while (true) { while (count == 0) ; // do nothing nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /consume item nextConsumed/ } Producer ConSUMER
Producer Consumer Producer Consumer or
1. Mutual Exclusion - If process Pi is executing in its critical section, then no other processes can be executing in their critical sections 2. Progress - If no process is executing in its critical section and there exist some processes that wish to enter their critical section, then the selection of the processes that will enter the critical section next cannot be postponed indefinitely **// no deadlock
i do { flag[i] = TRUE; turn = j; while (flag[j] && turn == j); critical section flag[i] = FALSE; remainder section } while (1) entry section exit section
do { flag1 = TRUE; turn = 2; while (flag2 && turn == 2); critical section….. flag1 = FALSE; remainder section….. } while (1) do { flag2 = TRUE; turn = 1; while (flag1 && turn == 1); critical section….. flag2 = FALSE; remainder section….. } while (1)
Shared Variables flag1, flag turn