Description
From the haskell-distributed/network-transport-tcp@3855e91:
Simply doing
thingToSend <- modifyMVar (....)
send thingToSendis not good enough, because now if we have to threads doing the above the sends
may be done in the wrong order.
Before haskell-distributed/network-transport-tcp@876a3dc it was true. But after sendOn was protected with MVar it seems that it became redundant, because, as @simonmar states in his book:
if a thread T is blocked in takeMVar and there are regular putMVar operations on the same MVar, it is guaranteed that at some point thread T’s takeMVar will return. In GHC, this guarantee is implemented by keeping blocked threads in a FIFO queue attached to the MVar...
In other words, the first thread called sendOn and blocked on MVar will be served first when the MVar will be available (if I understood correctly the book). So it seems that "simply doing" approach mentioned in the beginning will just do. No?
CC @edsko