Skip to content

Instantly share code, notes, and snippets.

Created May 24, 2013 08:46
Show Gist options
  • Save anonymous/5642179 to your computer and use it in GitHub Desktop.
Save anonymous/5642179 to your computer and use it in GitHub Desktop.
#!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