STEP 1:
-P1 puts 1 char into the buffer
STEP 2:
-P2 attempts put
-checks wait Loop-already a char-waits "P2 in Wait"
STEP 3:
-P3 attempts put
-checks wait Loop-already a char-waits "P2, P3 in Wait"
STEP 4:
-C1 attempts to get 1 char
-C2 attempts to get 1 char-blocks in entry to get
the method "C2 block"
-C3 attempts to get 1 char-blocks in entry to get
the method "C2, C3 block"
STEP 5:
-C1 is executing the get
method-gets the char, calls notify
, exits method
-The notify
wakes up P2
-but, C2 enters method before P2 can (P2 must reacquire the lock), so P2 blocks on entry to the put
method "P3 Wait" "P2, C3 Blocking
-C2 checks wait loop, no more chars in buffer, so Waits "P3, C2 Waiting" "P2, C3 block"
-C3 enters method after C2, but before P2, checks wait loop, no more chars in buffer, so Waits "C3, C2, P3 Wait" "P2 block"
STEP 6:
-Now:there is P3, C2, and C3 waiting!
-finally P2 acquires the lock, puts a char in the buffer, calls notify, exits method "P2 finally grabbed the lock"
STEP 7:
-P2 ' s notification wakes P3 (remember any thread can be woken) "P3 was notified"
-P3 checks the wait loop condition, there is already a char in the buffer, so waits. "P3, C2, C3 Wait" "Block queue is empty"
-NO more THREADS to call NOTIFY and three THREADS permanently suspended!