Question: 2. Given the following producer&consumer problem solution, what is the potential risk in the code when the solution is running on a single CPU,
2. Given the following producer&consumer problem solution, what is the potential risk in the code when the solution is running on a single CPU, multitasking operating system? Assume we need run multiple producers and consumers at the same time, modify the code to remove the risk using any solution that is proper. (10 pt) Producer: while (true) { } /* produce an item and put in nextProduced */ BUFFER_SIZE) while (count Consumer: while (true) { } == ; // do nothing buffer [in] = nextProduced; in = (in + 1) % BUFFER_SIZE; count++; while (count = 0) ; // do nothing = nextConsumed = buffer[out]; out = (out + 1) % BUFFER_SIZE; count--; /* consume the item in nextConsumed
Step by Step Solution
3.51 Rating (154 Votes )
There are 3 Steps involved in it
The code has a potential risk of race conditions when running on a single CPU multit... View full answer
Get step-by-step solutions from verified subject matter experts
