diff options
Diffstat (limited to 'lib/thread.rb')
-rw-r--r-- | lib/thread.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/thread.rb b/lib/thread.rb index 58c4f6b9e6..494a5b33e4 100644 --- a/lib/thread.rb +++ b/lib/thread.rb @@ -355,6 +355,22 @@ class SizedQueue < Queue def num_waiting @waiting.size + @queue_wait.size end + + # + # Removes all objects from the queue and wakes waiting threads, if any. + # + def clear + @mutex.synchronize do + @que.clear + begin + until @queue_wait.empty? + @queue_wait.shift.wakeup + end + rescue ThreadError + retry + end + end + end end # Documentation comments: |