"warning: fork terminates thread"

I'm not really troubled by this much, but I want to understand it.

Apparently there's no way to carry a running thread across a fork.
This is fine -- no one should try that anyway IMO.

My concerns are:
1. The phrasing makes it sound as though the thread in the parent
    process is terminated when a fork happens. This, fortunately,
    is not the case.
2. Sometimes I get this message when I think there should be no
    threads still running. Is it possible that the thread is a
    "false positive" or something? Is there such a thing as a
    zombie thread?
3. And finally, is there a way to disable this specific warning?

Thanks,
Hal

Hal Fulton wrote:

I'm not really troubled by this much, but I want to understand it.

Apparently there's no way to carry a running thread across a fork.
This is fine -- no one should try that anyway IMO.

My concerns are:
1. The phrasing makes it sound as though the thread in the parent
   process is terminated when a fork happens. This, fortunately,
   is not the case.

I guess it means the thread is terminated in the child, as soon as as the child starts up, as you've probably figured out. But it does sound alarming.

2. Sometimes I get this message when I think there should be no
   threads still running. Is it possible that the thread is a
   "false positive" or something? Is there such a thing as a
   zombie thread?

Hm. Try dumping Thread.list.inspect before forking?

3. And finally, is there a way to disable this specific warning?

Looks like your wish will soon come true:

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/95802

Btw, there's one situation where this warning is, well, educational. When you fork while another thread holding a lock of some kind (e.g., a Mutex). The lock will remain locked forever in the child, because the only thread that can unlock it is gone. (I once adapted the Mutex class to avoid getting bitten by this.)

i use this

   def tfork(*args, &block)
     v = $VERBOSE
     begin
       $VERBOSE = nil
       fork(*args, &block)
     ensure
       $VERBOSE = v
     end
   end

it shuts up the warnings

-a

···

On Mon, 21 Jun 2004, Hal Fulton wrote:

I'm not really troubled by this much, but I want to understand it.

Apparently there's no way to carry a running thread across a fork.
This is fine -- no one should try that anyway IMO.

My concerns are:
1. The phrasing makes it sound as though the thread in the parent
   process is terminated when a fork happens. This, fortunately,
   is not the case.
2. Sometimes I get this message when I think there should be no
   threads still running. Is it possible that the thread is a
   "false positive" or something? Is there such a thing as a
   zombie thread?
3. And finally, is there a way to disable this specific warning?

Thanks,
Hal

--

EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
PHONE :: 303.497.6469
A flower falls, even though we love it; and a weed grows, even though we do
not love it. --Dogen

===============================================================================