Skip to content

Instantly share code, notes, and snippets.

@tamtam180
Created January 3, 2017 13:25
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 tamtam180/817c00106bc30972a179b2687cf43b03 to your computer and use it in GitHub Desktop.
Save tamtam180/817c00106bc30972a179b2687cf43b03 to your computer and use it in GitHub Desktop.
why..?
# irb
2.3.1 :001 > q = Queue.new
=> #<Thread::Queue:0x00000002150908>
2.3.1 :002 > q.push(:a)
=> #<Thread::Queue:0x00000002150908>
2.3.1 :003 > q.push(:b)
=> #<Thread::Queue:0x00000002150908>
2.3.1 :004 > q.pop
=> :a
2.3.1 :005 > q.pop
=> :b
2.3.1 :006 > q.pop
fatal: No live threads left. Deadlock?
from (irb):6:in `pop'
from (irb):6
from /usr/local/rvm/rubies/ruby-2.3.1/bin/irb:11:in `<main>'
@tamtam180
Copy link
Author

tamtam180 commented Jan 3, 2017

Personally I think q.pop(false) is blocked when queue is empty.
ruby version: ruby 2.3.1p112

@tamtam180
Copy link
Author

q.popでblockしちゃうと他にpushできるスレッドが無いから、そのまま停止してしまうからか。

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