Issue #8185 has been updated by drbrain (Eric Hodel).

Category set to core
ruby -v set to 2.0.0p100


----------------------------------------
Bug #8185:  Thread/fork issue
https://bugs.ruby-lang.org/issues/8185#change-38034

Author: Anonymous
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 
ruby -v: 2.0.0p100


 Hello all,
 
 I've found an issue where calling fork inside a thread, and passing a block
 to the fork, causes the forked process to continue after the block.  I've
 reproduced the issue on the following versions of ruby:
 ruby 2.0.0p100 (2013-03-27 revision 39954) [x86_64-darwin10.8.0]
 ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin10.8.0]
 
 Here is the script I used to reproduce:
 
 1000.times do |j|
   puts "run #{j}"
   threads = []
   100.times do |i|
     threads << Thread.new(i) do |local_i|
       opid = fork do
         # exit!(true) # fixes the issue
         # exit(true) # doesn't fix the issue
         # no 'exit' also exhibits issue
       end
       ::Process.waitpid(opid, 0)
       File.open("/tmp/test_thread_fork_#{local_i}.pid", "w") {|f| f.write
 "1" }
     end
   end
   threads.map { |t| t.join }
 
   borked = false
   100.times do |i|
     fn = "/tmp/test_thread_fork_#{i}.pid"
     contents = File.read(fn)
     if contents.size > 1
       puts "file #{fn} was written to many times (#{contents})"
       borked = true
     end
   end
   exit(false) if borked
 end
 
 As you can see from the comments inside the fork I can work around the
 issue by using "exit!".  I am correct in understanding that there should be
 no case in which the file is written to multiple times, correct?
 
 Thank you,
 Jason Gladish


-- 
http://bugs.ruby-lang.org/