Class: CompTree::Queue
- Inherits:
-
Object
- Object
- CompTree::Queue
- Defined in:
- lib/comp_tree/queue/queue_18.rb,
lib/comp_tree/queue/queue_19.rb
Overview
minimal version of standard Queue
Instance Method Summary collapse
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
- #pop ⇒ Object
- #push(object) ⇒ Object
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
9 10 11 12 |
# File 'lib/comp_tree/queue/queue_18.rb', line 9 def initialize @queue = [] @waiting = [] end |
Instance Method Details
#pop ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/comp_tree/queue/queue_18.rb', line 22 def pop while (Thread.critical = true ; @queue.empty?) @waiting.push Thread.current Thread.stop end @queue.shift ensure Thread.critical = false end |
#push(object) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/comp_tree/queue/queue_18.rb', line 14 def push(object) Thread.critical = true @queue.push object thread = @waiting.shift and thread.wakeup ensure Thread.critical = false end |