If there were 1 ms transactions occurring every 100 ms, does this mean that a transaction that takes 200 ms to process will never end?
Transactions only conflict if they relate to the same TVar
s, therefore, if some of the 1 ms transactions avoid all the variables affected by the 200 ms transactions, then they can complete 200 ms. Moreover, since the STM
monad is pretty strict about what is allowed inside (only memory access and clean calculations!), It is very unusual to have such a mismatch between transaction durations; as a rule, they will be only for reading or writing several files, and all IO
and other calculations will be performed outside the transaction. Moreover, regardless of whether a transaction is permanently blocked by other transactions, this is a planning problem; I am not 100% sure that it looks like a GHC scheduler, but it seems plausible that it prefers older (or higher speeds) transactions.
However, livelock is a very real problem with STM
, and about the same insidious and just as difficult reason as a dead end in more traditional concurrency implementations.
How does TVar work?
You might like this article .
source share