Created
May 24, 2013 08:46
-
-
Save anonymous/5642179 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!ruby | |
trap("INT") do | |
puts "in int" | |
10.times do | |
masters = Thread.list.select { |t| t[:master] } | |
if masters.count > 0 | |
masters.first[:terminate] = true | |
masters.first.join | |
break | |
else | |
puts "retrying main thread kill in one second" | |
sleep 1 | |
end | |
end | |
# put exit here -- not here so we can test races | |
end | |
10.times do | |
Process.kill "INT", Process.pid | |
Thread.new do | |
Thread.current[:master] = true | |
loop do | |
if Thread.current[:terminate] | |
puts "exiting" | |
break | |
else | |
sleep 1 | |
end | |
end | |
end | |
sleep 1 | |
end | |
p Thread.list.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment