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

Simon Marechal simon at banquise.net
Mon Oct 15 10:45:06 CEST 2012


On 15/10/2012 09:47, Michael Snoyman wrote:
> With the program at the end of this email, I would expect that, once per
> second, I would get a message printed from each forkIO'd green thread,
> the forked process, and the master process. And if I spawn 8 or less
> child threads that's precisely what happens. However, as soon as I up
> that number to 9, the child process is never run. The process is,
> however, created, as can be confirmed by looking at the process table.

FWIW I can reproduce this problem. The strace in both cases is very
different. In the non threaded runtime, everything works as you expect:

7519  select(2, [], [1], NULL, {0, 0})  = 1 (out [1], left {0, 0})
7519  write(1, "starting child\n", 15)  = 15
7519  select(2, [], [1], NULL, {0, 0})  = 1 (out [1], left {0, 0})
7519  write(1, "(7519,\"child\",0)\n", 17) = 17
7519  timer_settime(0x3, 0, {it_interval={0, 0}, it_value={0, 0}}, NULL) = 0
7519  select(0, [], [], NULL, {0, 999994} <unfinished ...>
7519  <... select resumed> )            = 0 (Timeout)
7519  timer_settime(0x3, 0, {it_interval={0, 10000000}, it_value={0,
10000000}},  <unfinished ...>
7519  <... timer_settime resumed> NULL) = 0
7519  select(2, [], [1], NULL, {0, 0} <unfinished ...>
7519  <... select resumed> )            = 1 (out [1], left {0, 0})
7519  write(1, "(7519,\"child\",1)\n", 17 <unfinished ...>

In the threaded case, it:
* closes FD 3,4,5,6
* epoll_create, pipe, all kind of things
* clones twice
* ???

It seems that forkProcess is implemented entirely differently in the
threaded runtime.



More information about the Haskell-Cafe mailing list