fork and ghc

Simon Marlow simonmarhaskell at gmail.com
Wed Aug 9 05:15:45 EDT 2006


John Meacham wrote:
> I want to modify jhc to take advantage of mutiple CPUs to help mitigate
> its prodigious computational requirements and was curious how well ghc
> compiled programs deal with forking?
> 
> my initial plan is that once jhc determines which modules need to be
> recompiled, it will fork(2) off processes down each pass that can be
> done in parallel. however, I have no idea what the effect of just
> calling fork on the ghc runtime will be. both parent and child will
> continue on compiling code, so it won't be immediatly followed by an
> exec.

We provide System.Posix.forkProcess, which is a "controlled" version of fork. 
It probably works ok in the single-threaded runtime, but I'd say it's probably 
slightly dubious in the threaded runtime especially if you're planning on using 
it for more than just fork/exec.

POSIX puts some tight restrictions on what you can do in the child of a fork in 
a multi-threaded process (only async-signal-safe operations may be used).

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list