[GHC] #15136: High CPU when asynchronous exception and unblocking retry on TVar raced

GHC ghc-devs at haskell.org
Thu Jul 12 19:06:38 UTC 2018


#15136: High CPU when asynchronous exception and unblocking retry on TVar raced
-------------------------------------+-------------------------------------
        Reporter:  nshimaza          |                Owner:  osa1
            Type:  bug               |               Status:  patch
        Priority:  highest           |            Milestone:  8.6.1
       Component:  Runtime System    |              Version:  8.4.2
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  Runtime crash     |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):  Phab:D4956
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Ben Gamari <ben@…>):

 In [changeset:"7fc418df856d9b58034eeec48915646e67a7a562/ghc"
 7fc418df/ghc]:
 {{{
 #!CommitTicketReference repository="ghc"
 revision="7fc418df856d9b58034eeec48915646e67a7a562"
 Fix deadlock between STM and throwTo

 There was a lock-order reversal between lockTSO() and the TVar lock,
 see #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 #15136 doesn't deadlock any more.

 Reviewers: bgamari, osa1, erikd

 Reviewed By: osa1

 Subscribers: rwbarton, thomie, carter

 GHC Trac Issues: #15136

 Differential Revision: https://phabricator.haskell.org/D4956
 }}}

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15136#comment:12>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list