# Operating Systems Exam 3 v2

Consider the sequence of code shown at the right, where blue "producer" code to implement counter++ is interspersed with gold "consumer" code to implement counter--. How is it possible that the code could interleave in this way?
Click the card to flip 👆
1 / 38
Terms in this set (38)
It could interleave if the blue code starts running, but then that process running that code gets taken off the CPU by the CPU scheduler, and then the process running the gold code is put onto the CPU by the CPU scheduler. It could also happen in a multiprocessor system if the blue code is on one processor and the gold code is on another processor. In either case, the final result for counter could be incorrect. Treating the code as a critical section would have avoided this problem
Any solution to the critical-section problem must satisfy the progress condition, which says: 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. What does that mean?
Consider the synchronization Algorithm 1 shown in class. The code for one process, p1,is shown at the right; the code for the other process, p2, is similar.

a). Does this algorithm enforce mutual exclusion? Explain.

b). Does this algorithm avoid dead lock? Explain

c). What is the primary deficiency with this algorithm?
a). Yes, a process can only enter the critical section at a time - if it is turn.

b). Yes, since they take turns one process should always be able to enter the critical section

c). It forces the processes to take turns in a strict alternation, so if one process wants to enter the critical section more frequently than the other, it cannot. Finally, it wastes time busy waiting