Module: ImprovedQueue
- Defined in:
- lib/improved-queue.rb
Overview
A simple elaboration on Ruby’s native SizedQueue which allows using the queue object to re-awaken a blocked thread and cause it to abandon its blocking enqueue/dequeue operation. Useful for simplifying program logic, reducing the need for external flags/Muteces (yes, I said Muteces), and for cleanly resolving queues on program termination without risk of data loss or deadlock.
Why use this queue? There are two reasons. For one thing, under several circumstances it is considerably faster than Ruby’s native SizedQueue. I admit I’m not entirely sure why, but I have tested this on multiple platforms and it seems to hold true as a generality. You can feel free to confirm or dispel that this advantage holds for your use case at your own leisure.
The second reason is the aforementioned simplification of program logic. In the case that all data passing through the queues must be preserved on program termination, SizedQueue can require some elaborate trickery to ensure that even the most remote possibility of deadlock is removed. ImprovedSizedQueue solves this problem by making it possible to use the queue to pass control messages between threads, irrespective of the queue’s actual content.
- Version
-
1.0
- Author
-
Lincoln McCormick ([email protected])
- Copyright
-
Copyright © 2013 Lincoln McCormick
- License
-
GNU General Public License version 3
- Requires
-
Ruby 1.9
– This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <www.gnu.org/licenses/>. ++
:title:ImprovedQueue
Defined Under Namespace
Classes: ImprovedSizedQueue, UnblockError
Class Method Summary collapse
-
.new(size) ⇒ Object
Returns a new instance of ImprovedQueue::ImprovedSizedQueue.
Class Method Details
.new(size) ⇒ Object
Returns a new instance of ImprovedQueue::ImprovedSizedQueue. Note: size must be a positive integer >= 2
465 466 467 |
# File 'lib/improved-queue.rb', line 465 def new(size) ImprovedSizedQueue.new size end |