From: Eleanor McHugh Date: 2009-06-24T02:48:33+09:00 Subject: Re: Threads + Forks in Ruby 1.9.1p129 On 23 Jun 2009, at 17:24, Lee Hinman wrote: > On Tue, Jun 23, 2009 at 10:14 AM, Roger Pack > wrote: >> >> Lee Hinman wrote: >>> Hey All, >>> I'm seeing some weirdness trying to get Ara's forkoff gem working on >>> ruby 1.9.1. >> >> Maybe it doesn't copy the threads over right or something? >> http://ruby-doc.faithpromotingstories.org/doc/ruby-1.9.1-p129/classes/Kernel.html#M002828 >> seems to say that "threads are not copied" or something [?] > > I'm wondering if this text might have something to do with it (from > the fork man page, > http://www.opengroup.org/onlinepubs/000095399/functions/fork.html ): [snip] > The line "If a multi-threaded process calls fork(), the new process > shall contain a replica of the calling thread and its entire address > space, possibly including the states of mutexes and other resources" > seems to be important to this issue, however I'm not familiar enough > with Ruby's internals to understand how this would cause the > deadlock/hanging, does anyone have any ideas? POSIX threads are managed by the kernel rather than the process, hence when fork copies a process to a child it only launches the currently active thread. This is analogous to the situation with file descriptors where the descriptors are copied into the new process but they still point to the same underlying data structures rather than duplicates. On 1.8.6 with green threads a fork() could result in a child process with all the threads present in the parent process, however I know that with the Apple default install of 1.8.6 on Leopard this is not the case. As I don't have the time to dig into the sources right now I'll float the hypothesis that 1.8.6 is being built with pthreads. Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason