From: Tanaka Akira Date: 2013-04-02T10:03:28+09:00 Subject: [ruby-core:53887] Re: Thread/fork issue 2013/3/30 Tanaka Akira : > 2013/3/30 Jason Gladish : >> >> 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: > > It seems buffered IO data is flushed in several child processes. > The contorol itself dosen't continue after the block. > > exit!(true) solves the problem because it doesn't flush IO. > Also, if you use f.syswrite instead of f.write, the problem disappears. > > The problem is reproduced more reliably by sleeping a second after f.write. I wrote a simple script to reproduce the problem. This script doesn't use multi-threads. % ./ruby -ve ' open("zz", "w") {|f| f.print "foo\n" Process.wait fork {} p $$ } ' ruby 2.1.0dev (2013-04-01 trunk 40040) [x86_64-linux] 4784 % cat zz foo foo The buffered data in f, "foo\n", is flushed in the child process and the parent process. So zz has two "foo\n". -- Tanaka Akira