Skip to content

Instantly share code, notes, and snippets.

@mezis
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mezis/9536577 to your computer and use it in GitHub Desktop.
Save mezis/9536577 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Thread, fork, and try to trigger deadlocks
#
def make_noise
$stdout.write("\000")
end
[1,2].each do
Thread.new do
while true
make_noise
end
end
end
while true
pid = fork { make_noise }
Process.waitpid(pid)
end
@mezis
Copy link
Author

mezis commented Mar 13, 2014

This will cause deadlocks in the forked processes in MRI 1.9.3, but not in 1.8.7 or 2.0+.

It surfaces with any output file, with or without flushing, and starting from 2 extra threads in the main process (1 extra thread only does not trigger the issue).

@mezis
Copy link
Author

mezis commented Mar 13, 2014

1.9.3-p545 fixes the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment