Closed kazu-yamamoto closed 4 months ago
Multiple threads may execute printResultSTM with the same result, like following event sequence:
By putTMVar
from the thread that outputs the results, make others wait.
https://github.com/kazu-yamamoto/dnsext/commit/fe0a206f3479321682cf0ca326e0952340add18e
Ah! Thanks. Let's merge.
thread1: read
False
from tvar thread2: readFalse
from tvar thread1: runprintResultSTM
thread2: runprintResultSTM
thread1: write True to tvar thread2: write True to tvar
This never happens because STM actions run atomically. Reverting fe0a206.
thread1: read `False` from tvar thread2: read `False` from tvar thread1: run `printResultSTM` thread2: run `printResultSTM` thread1: write True to tvar thread2: write True to tvar
Sorry.
When thread2 does printResultSTM
, it knows it broke thread1's transaction, so thread2 retries.
So the original program is safe.
Using STM log for atomicity.