How to synchronously shutdown the event manager loop

Bas van Dijk v.dijk.bas at gmail.com
Wed Aug 31 00:15:32 CEST 2011


On 30 August 2011 17:39, Bryan O'Sullivan <bos at serpentine.com> wrote:
> On Tue, Aug 30, 2011 at 6:49 AM, Bas van Dijk <v.dijk.bas at gmail.com> wrote:
>>
>> As you see I also kill the thread which is running the event manager
>> loop. However I think this is not the right way to do it because when
>> I use the library I see the following message being continually
>> printed after the `Ctx` is finalized:
>>
>> ghc: ioManagerWakeup: write: Bad file descriptor
>
> I'm afraid we don't provide a way to shut down an event manager
> synchronously at the moment. You'll have to submit a patch if you want to
> add that capability.

I see what I can do. I'm first going to export the 'finished' function
from GHC.Event and use that to wait till the loop finishes and see if
that solves my problem.

BTW to reproduce the problem (if you're interested) you can use the
following program: (make sure to use the latest usb sources from git)

import System.USB (newCtx)
import Control.Concurrent (threadDelay)
import System.Mem (performGC)

main :: IO ()
main = do
  _ <- newCtx
  threadDelay 2000000
  performGC
  threadDelay 2000000

running this yields:

example: ioManagerWakeup: write: Bad file descriptor
example: ioManagerDie: write: Bad file descriptor

> Perhaps you could add a way to specify an "onShutdown
> :: IO ()" hook that would be called by the event manager thread once it
> shuts down.

That's a possibility.

BTW is there a reason 'shutdown' needs to be asynchronous or was it
just easier to implement it this way? Otherwise I think a synchronous
'shutdown' is easier to work with.

Regards,

Bas



More information about the Glasgow-haskell-users mailing list