forkIO and not -threaded
Simon Marlow
simonmarhaskell at gmail.com
Wed Aug 2 08:14:30 EDT 2006
Duncan Coutts wrote:
> On Sat, 2006-07-29 at 01:29 +0100, Neil Mitchell wrote:
>
>>Hi,
>>
>>main = do
>> forkIO $ print "yes"
>> print "done"
>>
>>Compiled without -threaded, on 6.2.2 gives
>>
>>"yes"
>>"done"
>>
>>on 6.4.2
>>
>>"done"
>>
>>Seems the semantics of forkIO in this case has changed completely?
>
>
> Actually what changed is whether all threads have to finish or just the
> main thread.
>
> So what happens now with your code is that the main thread terminates
> the whole program before the other thread gets a chance to run.
Nothing has really changed here at all: the program has non-deterministic
behaviour. The runtime doesn't wait for all threads to finish before exiting,
it exits as soon as the main thread has finished, see the docs:
http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent.html#9
Cheers,
Simon
More information about the Glasgow-haskell-bugs
mailing list