Question: 17. Consider the solution to the Producer-Consumer problem that we have studied in Synchronization. As you are aware that this solution uses a shared

17. Consider the solution to the Producer-Consumer problem that we have studied in Synchronization. As you

17. Consider the solution to the Producer-Consumer problem that we have studied in Synchronization. As you are aware that this solution uses a shared variable counter that is used by both the Producer and the Consumer processes. You may refer to your class notes/book for having a look at the pseudocode. For this problem, assume BUFFER_SIZE = 15. The rest of the producer-consumer code is same as that we had discussed during lecture. Suppose that there is only one producer process and one consumer process. Both processes are executing concurrently. Currently, counter = 8. At the machine language level, counter++ and counter-- are implemented in the same manner that we have discussed in class. Producer uses register and consumer uses register2. Now consider the following sequence of interleaved machine-level instructions shown in the Table below. What is the final value of the counter variable? Only write the answer. You do not have to show any calculation or give any explanation. Time Instant To T T2 T3 T4 Ts Execution consumer executes register2 = counter consumer executes register2 = register2 - 1 producer executes register1 = counter consumer executes counter = register2 producer executes register1 = register1 + 1 producer executes counter = register1

Step by Step Solution

3.41 Rating (154 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Based on the given sequence of interleaved machinelevel instructions lets analyze the c... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!