Sha256: 4f190da7120930cb4ed37225da0fc86ca2e172a87b5547a3c662cea00abd8c5c

Contents?: true

Size: 2 KB

Versions: 16

Compression:

Stored size: 2 KB

Contents

# TODO: Deprecate
# require 'thread'
# begin
#   require 'fasttread'
# rescue LoadError
# end
# 
# class ThreadPool
#   class Worker
#     def initialize(thread_queue)
#       @mutex = Mutex.new
#       @cv = ConditionVariable.new
#       @queue = thread_queue
#       @running = true
#       @thread = Thread.new do
#         @mutex.synchronize do
#           while @running
#             @cv.wait(@mutex)
#             block = get_block
#             if block
#               @mutex.unlock
#               block.call
#               @mutex.lock
#               reset_block
#             end
#             @queue << self
#           end
#         end
#       end
#     end
# 
#     def name
#       @thread.inspect
#     end
# 
#     def get_block
#       @block
#     end
# 
#     def set_block(block)
#       @mutex.synchronize do
#         raise RuntimeError, "Thread already busy." if @block
#         @block = block
#         # Signal the thread in this class, that there's a job to be done
#         @cv.signal
#       end
#     end
# 
#     def reset_block
#       @block = nil
#     end
# 
#     def busy?
#       @mutex.synchronize { !@block.nil? }
#     end
# 
#     def stop
#       @mutex.synchronize do
#         @running = false
#         @cv.signal
#       end
#       @thread.join
#     end
#   end
# 
#   attr_accessor :max_size
# 
#   def initialize(max_size = 10)
#     @max_size = max_size
#     @queue = Queue.new
#     @workers = []
#   end
# 
#   def size
#     @workers.size
#   end
# 
#   def busy?
#     @queue.size < @workers.size
#   end
# 
#   def shutdown
#     @workers.each { |w| w.stop }
#     @workers = []
#   end
# 
#   alias :join :shutdown
# 
#   def process(block=nil,&blk)
#     block = blk if block_given?
#     worker = get_worker
#     worker.set_block(block)
#   end
# 
#   private
# 
#   def get_worker
#     if !@queue.empty? or @workers.size == @max_size
#       return @queue.pop
#     else
#       worker = Worker.new(@queue)
#       @workers << worker
#       worker
#     end
#   end
# 
# end

Version data entries

16 entries across 16 versions & 3 rubygems

Version Path
auser-poolparty-1.1.6 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.1.7 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.0 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.1 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.10 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.11 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.12 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.2 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.3 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.4 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.7 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.8 lib/poolparty/modules/thread_pool.rb
auser-poolparty-1.2.9 lib/poolparty/modules/thread_pool.rb
fairchild-poolparty-1.1.5 lib/poolparty/modules/thread_pool.rb
fairchild-poolparty-1.2.12 lib/poolparty/modules/thread_pool.rb
poolparty-1.2.2 lib/poolparty/modules/thread_pool.rb