[Haskell-cafe] forkProcess, forkIO, and multithreaded runtime

Chris Dornan chris at chrisdornan.com
Mon Jan 21 14:14:44 CET 2013

I am also sorry to be late on this but I have run into the same problem
trying to demonise a programme on 7.4.2. My solution was to get a shell
wrapper to run the daemon in debug mode (I.e., sans fork) and get the shell
script to do the demonising.

Other than this I have found the threaded RTS to be sound and I am quite
reliant on it. So, where things that run ‹threaded are concerned, no
forkProcess calls for me until I can better understand this better.

If anybody does think they understand what is going on here it would be
great if they could write it up. IMHO, either the current notes on
forkProcess don't go far enough, or there is a bug needing a workaround
until the platform gets fixed.


From:  Mark Lentczner <mark.lentczner at gmail.com>
Date:  Sunday, 20 January 2013 23:15
To:  haskell <haskell-cafe at haskell.org>
Cc:  Mike Meyer <mwm at mired.org>
Subject:  Re: [Haskell-cafe] forkProcess, forkIO, and multithreaded runtime

Sorry to be reviving this thread so long after.... but I seem to be running
into similar issues as Michael S. did at the start.

In short, I'm using forkProcess with the threaded RTS, and see occasional
* I see these only on Linux. On Mac OS X, I never do.
* I'm using GHC 7.4.2
* I noticed the warning in the doc for forkProcess, but assumed I was safe,
as I wasn't holding any shared resources at the time of the fork, and no
shared resources in the program are used in the child.
* WIth gdb, I've traced the hang to here in the run-time: forkProcess >
discardTasksExcept > freeTask > closeMutex(&task->lock) >
The discussion in this thread leaves me with these questions:
* Is there reason to think the situation has gotten better in 7.6 and later?
* Isn't the only reason System.Process is safer because it does an immediate
exec in the child? Alas, I really want to just fork() sometimes.
* Is it really true that even if my program has no shared resources with the
child, that the IO subsystem and FFI system do anyway? Surely the RTS would
take care of doing the right thing with those, no?
* There should be no concern with exec w.r.t. library invariants since exec
is wholesale replacement - all the libraries will reinitialize. Is there a
problem here I'm missing?
Alas, I've stopped using the threaded RTS until I understand this better.

- Mark
_______________________________________________ Haskell-Cafe mailing list
Haskell-Cafe at haskell.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130121/67ae43e8/attachment.htm>

More information about the Haskell-Cafe mailing list