Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Synchronize on a mutex

  • Loading branch information...
commit ca5208b17e79df194309f1c7cdaa62f6d0db71f6 1 parent cf0fc65
Seth Morabito authored
Showing with 13 additions and 8 deletions.
  1. +13 −8 server/lib/bdrb_thread_pool.rb
View
21 server/lib/bdrb_thread_pool.rb
@@ -23,6 +23,7 @@ def initialize(master,size,logger)
@threads = []
@work_queue = Queue.new
@size.times { add_thread }
+ @mutex = Monitor.new
end
# can be used to make a call in threaded manner
@@ -48,7 +49,9 @@ def initialize(master,size,logger)
def defer(method_name,args = nil)
job_key = Thread.current[:job_key]
persistent_job_id = Thread.current[:persistent_job_id]
- @work_queue << WorkData.new(args,job_key,method_name,persistent_job_id)
+ @mutex.synchronize do
+ @work_queue << WorkData.new(args,job_key,method_name,persistent_job_id)
+ end
end
# Start worker threads
@@ -57,13 +60,15 @@ def add_thread
Thread.current[:job_key] = nil
Thread.current[:persistent_job_id] = nil
while true
- begin
- task = @work_queue.pop
- Thread.current[:job_key] = task.job_key
- Thread.current[:persistent_job_id] = task.persistent_job_id
- block_result = run_task(task)
- rescue BackgrounDRb::InterruptedException
- logger.info("BackgronDRb thread interrupted: #{Thread.current.inspect}")
+ @mutex.synchronize do
+ begin
+ task = @work_queue.pop
+ Thread.current[:job_key] = task.job_key
+ Thread.current[:persistent_job_id] = task.persistent_job_id
+ block_result = run_task(task)
+ rescue BackgrounDRb::InterruptedException
+ logger.info("BackgrounDRb thread interrupted: #{Thread.current.inspect}")
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.