[Haskell-cafe] Re: Waiting for thread to finish
Simon Marlow
simonmarhaskell at gmail.com
Tue Dec 11 12:01:30 EST 2007
ChrisK wrote:
> That is new. Ah, I see GHC.Conc.forkIO now has a note:
>
>> GHC note: the new thread inherits the /blocked/ state of the parent
>> (see 'Control.Exception.block').
>
> BUT...doesn't this change some of the semantics of old code that used forkIO ?
Yes, it is a change to the semantics. I assumed (naively) that virtually
nobody would be using forkIO inside block, and so the change would be
benign. It is (another) departure from the semantics in the Asynchronous
Exceptions paper. Still, I think this is the right thing.
> I wanted a way to control the blocked status of new threads, since this makes it
> easier to be _sure_ some race conditions will never happen.
>
> And so my new preferred way of writing this is now:
>
>> -- we are in parent's blocked state, so make the ticker explicit:
>> res <- bracket (forkIO (unblock ticker))
>> killThread
>> const act -- act runs in parent's blocked state
>
In this case the unblock isn't strictly necessary, because the ticker
thread spends most of its time in threadDelay, which is interruptible anyway.
Cheers,
Simon
More information about the Haskell-Cafe
mailing list