[GHC] #5553: sendWakeup error in simple test program with MVars and killThread

GHC ghc-devs at haskell.org
Wed Dec 7 00:44:33 UTC 2016


#5553: sendWakeup error in simple test program with MVars and killThread
-------------------------------------+-------------------------------------
        Reporter:  bit               |                Owner:
            Type:  bug               |               Status:  new
        Priority:  high              |            Milestone:  7.4.2
       Component:  Runtime System    |              Version:  8.0.1
      Resolution:                    |             Keywords:
Operating System:  Linux             |         Architecture:  x86
 Type of failure:  Incorrect result  |            Test Case:
  at runtime                         |
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------
Changes (by basvandijk):

 * cc: basvandijk, simonmar (added)
 * status:  closed => new
 * version:  7.2.1 => 8.0.1
 * resolution:  worksforme =>
 * owner:  tibbe =>


Comment:

 In a program at work I get exactly the same error.

 I'm on '''GHC-8.0.1'''.

 I'm using Don Stewarts [http://hackage.haskell.org/package/ghc-gc-tune
 ghc-gc-tune] to find the optimal GC settings for a server program. `ghc-
 gc-tune` expects the program to terminate. Since it's a server this
 doesn't happen. To fix this I wrap the program in `timeout --preserve-
 status 5` to terminate the server after 5 seconds. `ghc-gc-tune` will run
 the program many times with different `-H` and `-A` settings.

 Among other things, the program forks a thread which basically does the
 same thing as the `serverThread` of the OP:

 {{{
 tid <- forkIO $ forever $ threadDelay 5000000
 }}}

 The program ends with installing a signal handler for SIGTERM which will
 unlock a lock that the program is waiting on. Finally the forked thread is
 killed:

 {{{
 lock <- newEmptyMVar
 installHandler sigTERM (Catch $ putMVar lock ()) (Just fullSignalSet)
 takeMVar lock

 killThread tid
 }}}

 I believe the `sendWakeup` exception is thrown in `threadDelay`.

 I'm trying to reduce to program so it doesn't contain any proprietary code
 but so far I'm not succeeding.

 It appears that
 [https://github.com/ghc/ghc/blob/ghc-8.0/libraries/base/GHC/Event/TimerManager.hs#L128
 closeControl] is called before
 [https://github.com/ghc/ghc/blob/ghc-8.0/libraries/base/GHC/Event/TimerManager.hs#L204
 wakeManager]. Could it be that the `state` IORef is
 [https://github.com/ghc/ghc/blob/ghc-8.0/libraries/base/GHC/Event/TimerManager.hs#L124
 finalized] before we run `wakeManager`? If so, how can we ensure the
 garbage collector treats the IORef as reachable until after `wakeManager`?
 Maybe writing to it, as in:

 {{{
 wakeManager :: TimerManager -> IO ()
 wakeManager mgr = do
   sendWakeup (emControl mgr)
   atomicWriteIORef (emState mgr) $ \x -> (x, ())
 }}}

 ?

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


More information about the ghc-tickets mailing list