Homework 2 - Chapter 2 Questions 3, 4, and 7
Busy waiting is when a process runs continually checking whether a flag has been set (or a lock freed). Blocking involves the process not running until it is woken up to let it know that the resource is available.
It enforces mutual exclusion (i.e. it doesn't allow both processes in their critical sections at the same time), but it violates the "no process not in its critical section can cause another process to block" constraint.
If the count = count + 1 and count = count - 1 get interleaved, count may have an incorrect value. This
can result in trying to take something from an empty queue or put something on a full queue.
Assume count starts out as N-1, a consumer reduces it to N-2. Before the test of count == N-1, a producer runs making it N-1 again. Now, the consumer tests count == N-1 and gets preempted before it calls wakeup. The producer runs again, and now count = N. The producer continues and goes to sleep. The consumer wakes the producer which puts the item into the already full buffer.