Fix deadlock between STM and throwTo

Authored by simonmar on Jul 12 2018, 9:13 AM.


Fix deadlock between STM and throwTo

There was a lock-order reversal between lockTSO() and the TVar lock,
see Trac #15136 for the details.

It turns out we can fix this pretty easily by just deleting all the
locking code(!). The principle for unblocking a BlockedOnSTM thread
then becomes the same as for other kinds of blocking: if the TSO
belongs to this capability then we do it directly, otherwise we send a
message to the capability that owns the TSO. That is, a thread blocked
on STM is owned by its capability, as it should be.

The possible downside of this is that we might send multiple messages
to wake up a thread when the thread is on another capability. This is
safe, it's just not very efficient. I'll try to do some experiments
to see if this is a problem.

Test Plan: Test case from Trac #15136 doesn't deadlock any more.

Reviewers: bgamari, osa1, erikd

Reviewed By: osa1

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: Trac #15136

Differential Revision: