public
Last active

[TRIVIAL] the thread becomes dead after we get the value. also we can pass a timeout value to Thread#join and try to join afterwards

  • Download Gist
[TRIVIAL] thread_join_and_status.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
t = Thread.new { sleep 5; puts 1 }
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
t.join(1)
puts "status: #{t.status} on #{t.inspect}"
 
__END__
 
status: sleep on #<Thread:0x1d0ae48 sleep>
status: sleep on #<Thread:0x1d0ae48 sleep>
status: sleep on #<Thread:0x1d0ae48 sleep>
status: sleep on #<Thread:0x1d0ae48 sleep>
status: sleep on #<Thread:0x1d0ae48 sleep>
1
status: false on #<Thread:0x1d0ae48 dead>
status: false on #<Thread:0x1d0ae48 dead>
status: false on #<Thread:0x1d0ae48 dead>
status: false on #<Thread:0x1d0ae48 dead>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.