You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(case 1) 0???...???: the block is not written yet, cannot read, can write
54
+
(case 2) 1000...000: the block is just written, can read, cannot write
55
+
(case 3) 1???...???: the block is written and read by some readers, can read if not read, cannot write
56
+
(case 4) 1111...111: the block is written and read by all readers, cannot read, can write
57
+
58
+
State transition for readers:
59
+
60
+
When a reader finds a block that it can read (case 2 or 3), it can yield the block for caller to read.
61
+
Only after the caller finishes reading the block, the reader can mark the block as read.
62
+
Readers only mark the block as read (from 0 to 1), the writer marks the block as ready to read (from 1 to 0).
63
+
64
+
State transition for writer:
65
+
66
+
When the writer writes to a block (case 1 or 4), it first resets the written flag to 0, converting either case
67
+
to case 1. Then it can yield the block for caller to write. After the caller finishes writing the block, the writer
68
+
can reset the reader flags to 0, and mark the block as written (from 0 to 1).
69
+
NOTE: the order is important here, first reset the reader flags (so that we are still in case 1), then mark the block as written. The state transition is atomic. If we do it in the reverse order, it will go through case 3 and then back to case 2, and readers might read the intermediate case 3, which is not correct.
70
+
51
71
During creation, `name` is None and the buffer is created. We can pass the
52
72
created object to other processes by pickling it. The other processes will
53
73
get the name of the shared memory and open it, so that they can access the
0 commit comments