Is there any other documentation/discussion about the following design pattern (I'm not sure what it is called) from a well-known source? I'm almost 100% sure that the following will manage data safely between two (not more than two) processes, but would feel much better if I could find some more detailed information on why it works from a reputable source.
Suppose I have two processes A and B that are executing in parallel. They share the following data structure (in pseudo-C code):
struct Shared
{
bool ownedByA
Otherstuff otherstuff;
}
I can use the following pair of state machines to manage this shared data safely:
A:
state A.A (data is owned by A), entered on startup:
read/modify/write "otherstuff"
when done, goto A.Adone
state A.Adone
set ownedByA to false
goto state A.B
state A.B (data is owned by B):
if ownedByA is true, goto state A.A
otherwise stay in state A.B
B:
state B.A (data is owned by A), entered on startup:
if ownedByA is false, goto state B.B
otherwise stay in state B.A
state B.B (data is owned by B):
read/modify/write "otherstuff"
when done, go to B.Bdone
state B.Bdone:
set ownedByA to true
goto state B.A
We must ensure A.A's writes to "otherstuff" and A.Adone's write to ownedByA are in strict sequence ordering w/r/t memory visibility. Similarly for B.B and B.Bdone.
at startup:
1. Initialize ownedByA to true, A to the A.A state, B to the B.A state
2. start running state machines
(ensure that 1. happens-before 2.)