This commentary page describes a lot of the fine details of STM
in GHC, but I'd like clarity on a couple points.
First, is a nested transaction invalidated when variables accessed in the parent change?
For instance we have in thread A
:
takeTMVar a `orElse` takeTMVar b `orElse` takeTMVar c
Say that while A
is executing the nested transaction takeTMVar b
, another thread B
does a putTMVar a ()
; can thread A
successfully complete its nested transaction, or is it invalidated (this would strike me as wrong)?
A second point which I think I understand but wouldn't mind reassurance on: in the case where the entire top-level transaction described above for A
is retried and finally blocks, is it correct that A
will be awoken when any of a
, b
, or c
change?
Finally as a bonus, do the semantics of the transaction above change if we (or library authors) change orElse
to infixr
?
TMVar
was just the first example I could think of that was a simple transaction withretry
(i.e. the specific interaction of takes and puts and what calls retry isn't important). What I'm really trying to get at in my first question is whether there is contention between subtransactions in different threads operating on differentTVars
. If that doesn't make sense I'll try to clarify after I eat something – Titi