Java Reference
In-Depth Information
Initial State (buffer cells occupied: 0)
buffer cells: -1 -1 -1
---- ---- ----
WR
Producer writes 1 (buffer cells occupied: 1)
buffer cells: 1 -1 -1
---- ---- ----
R W
Consumer reads 1 (buffer cells occupied: 0)
buffer cells: 1 -1 -1
---- ---- ----
WR
Buffer is empty. Consumer waits.
Producer writes 2 (buffer cells occupied: 1)
buffer cells: 1 2 -1
---- ---- ----
R W
Consumer reads 2 (buffer cells occupied: 0)
buffer cells: 1 2 -1
---- ---- ----
WR
Producer writes 3 (buffer cells occupied: 1)
buffer cells: 1 2 3
---- ---- ----
W R
Consumer reads 3 (buffer cells occupied: 0)
buffer cells: 1 2 3
---- ---- ----
WR
Producer writes 4 (buffer cells occupied: 1)
buffer cells: 4 2 3
---- ---- ----
R W
Producer writes 5 (buffer cells occupied: 2)
buffer cells: 4 5 3
---- ---- ----
R W
Consumer reads 4 (buffer cells occupied: 1)
buffer cells: 4 5 3
---- ---- ----
R W
Producer writes 6 (buffer cells occupied: 2)
buffer cells: 4 5 6
---- ---- ----
W R
Fig. 23.19 | Producer and Consumer threads correctly manipulating a circular buffer. (Part 2 of 3.)
Search WWH ::




Custom Search