STM monad problem

前端 未结 3 365
死守一世寂寞
死守一世寂寞 2020-12-16 15:33

This is just a hypothetical scenario to illustrate my question. Suppose that there are two threads and one TVar shared between them. In one thread there is an atomically b

3条回答
  •  生来不讨喜
    2020-12-16 16:09

    STM prevents deadlock, but is still vulnerable to starvation. It is possible in a pathological case for the 1s atomic action to always aquire the resource.

    However, the changes of this happening are very rare -- I don't believe I've ever seen it in practice.

    For the semantics, see Composable Memory Transactions, section 6.5 "Progress". STM in Haskell guarantees only that a running transaction will successfully commit (i.e. no deadlock), but in the worst case an infinite transaction will block others.

提交回复
热议问题