Skip to content
Browse files

More playing around with mutex locking

  • Loading branch information...
1 parent 46cb615 commit c981c2eff47c237cf1f3a36ca19574f2017d7bcb Seth Morabito committed Nov 10, 2008
Showing with 9 additions and 6 deletions.
  1. +9 −6 server/lib/bdrb_thread_pool.rb
View
15 server/lib/bdrb_thread_pool.rb
@@ -47,9 +47,9 @@ def initialize(master,size,logger)
# assuming method is defined in rss_worker
def defer(method_name,args = nil)
- job_key = Thread.current[:job_key]
- persistent_job_id = Thread.current[:persistent_job_id]
@mutex.synchronize do
+ 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)
end
end
@@ -60,15 +60,18 @@ def add_thread
Thread.current[:job_key] = nil
Thread.current[:persistent_job_id] = nil
while true
- @mutex.synchronize do
- begin
+ begin
+ task = nil
+ @mutex.synchronize do
task = @work_queue.pop
+ end
+ if task
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
+ rescue BackgrounDRb::InterruptedException
+ logger.info("BackgrounDRb thread interrupted: #{Thread.current.inspect}")
end
end
end

0 comments on commit c981c2e

Please sign in to comment.
Something went wrong with that request. Please try again.