Skip to content

Instantly share code, notes, and snippets.

@mezis

mezis/threader.rb

Last active Aug 29, 2015
Embed
What would you like to do?
#!/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

This comment has been minimized.

Copy link
Owner Author

@mezis 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

This comment has been minimized.

Copy link
Owner Author

@mezis 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
You can’t perform that action at this time.