Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 System 2 I/ semaphores that synchronize access to sharedValue 3 Semaphore valueProduced new Semaphore(0); 4 Semaphore valueConsumed new Semaphore(1); 5 int sharedValue; // variable
1 System 2 I/ semaphores that synchronize access to sharedValue 3 Semaphore valueProduced new Semaphore(0); 4 Semaphore valueConsumed new Semaphore(1); 5 int sharedValue; // variable shared by producer and consumer 26 Consumer Thread 27 28 void main 7 startThreadsO; // initialize and launch both threads 9 Producer Thread 10 11 void main 30 int nextValue; //variable to store value consumed 31 2 while (!done) 13 14 15 int nextValueProduced; // variable to store value produced 34 P( valueProduced); //wait until value is produced 35 36 VvalueConsumed); /signal that value has been consumed 37 processTheValue(Cosumed);//process the value 38 while (Idone) nextValueConsumed-sharedValue; /critical section 17 18 19 nextValueProduced - generateTheValueO; //produce value P( valueConsumed); // wait until value is consumed sharedValue nextValueProduced; /critical section VC valueProduced) /signal that value has been produced 21 22 / end while 41end consumer thread 24 end producer thread 3. (10%) ClC2P1P2. Consider the simplified but still not normal case of CIC2P1P2 and explain how instruction sequence is 4. (10%) CI PIP2C2. Repeat Q3 with a different consumer producer sequence CIPI P2C2. 5. (9%) yP, combination. In slide #9 of MoreonSemaphores.ppt,, there is this statement vP-0 and vC-1 so that Producer and Consumer synchronizes (they actually lockstep so that producer can not out . All the other 3 combinations vP = 1. vC = 1: vP = 1. vC = 0; and vP = 0, vC = 0: do not work. Why? Explain wlhy the three other combinations vP-1, xC-1; vP-1, vC-0; and vP-0, 0; do not work. run consumer and consumer can not run faster than producer) 1 System 2 I/ semaphores that synchronize access to sharedValue 3 Semaphore valueProduced new Semaphore(0); 4 Semaphore valueConsumed new Semaphore(1); 5 int sharedValue; // variable shared by producer and consumer 26 Consumer Thread 27 28 void main 7 startThreadsO; // initialize and launch both threads 9 Producer Thread 10 11 void main 30 int nextValue; //variable to store value consumed 31 2 while (!done) 13 14 15 int nextValueProduced; // variable to store value produced 34 P( valueProduced); //wait until value is produced 35 36 VvalueConsumed); /signal that value has been consumed 37 processTheValue(Cosumed);//process the value 38 while (Idone) nextValueConsumed-sharedValue; /critical section 17 18 19 nextValueProduced - generateTheValueO; //produce value P( valueConsumed); // wait until value is consumed sharedValue nextValueProduced; /critical section VC valueProduced) /signal that value has been produced 21 22 / end while 41end consumer thread 24 end producer thread 3. (10%) ClC2P1P2. Consider the simplified but still not normal case of CIC2P1P2 and explain how instruction sequence is 4. (10%) CI PIP2C2. Repeat Q3 with a different consumer producer sequence CIPI P2C2. 5. (9%) yP, combination. In slide #9 of MoreonSemaphores.ppt,, there is this statement vP-0 and vC-1 so that Producer and Consumer synchronizes (they actually lockstep so that producer can not out . All the other 3 combinations vP = 1. vC = 1: vP = 1. vC = 0; and vP = 0, vC = 0: do not work. Why? Explain wlhy the three other combinations vP-1, xC-1; vP-1, vC-0; and vP-0, 0; do not work. run consumer and consumer can not run faster than producer)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started