Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

More playing around with mutex locking

  • Loading branch information...
commit c981c2eff47c237cf1f3a36ca19574f2017d7bcb 1 parent 46cb615
Seth Morabito authored

Showing 1 changed file with 9 additions and 6 deletions. Show diff stats Hide diff stats

  1. +9 6 server/lib/bdrb_thread_pool.rb
15 server/lib/bdrb_thread_pool.rb
@@ -47,9 +47,9 @@ def initialize(master,size,logger)
47 47 # assuming method is defined in rss_worker
48 48
49 49 def defer(method_name,args = nil)
50   - job_key = Thread.current[:job_key]
51   - persistent_job_id = Thread.current[:persistent_job_id]
52 50 @mutex.synchronize do
  51 + job_key = Thread.current[:job_key]
  52 + persistent_job_id = Thread.current[:persistent_job_id]
53 53 @work_queue << WorkData.new(args,job_key,method_name,persistent_job_id)
54 54 end
55 55 end
@@ -60,15 +60,18 @@ def add_thread
60 60 Thread.current[:job_key] = nil
61 61 Thread.current[:persistent_job_id] = nil
62 62 while true
63   - @mutex.synchronize do
64   - begin
  63 + begin
  64 + task = nil
  65 + @mutex.synchronize do
65 66 task = @work_queue.pop
  67 + end
  68 + if task
66 69 Thread.current[:job_key] = task.job_key
67 70 Thread.current[:persistent_job_id] = task.persistent_job_id
68 71 block_result = run_task(task)
69   - rescue BackgrounDRb::InterruptedException
70   - logger.info("BackgrounDRb thread interrupted: #{Thread.current.inspect}")
71 72 end
  73 + rescue BackgrounDRb::InterruptedException
  74 + logger.info("BackgrounDRb thread interrupted: #{Thread.current.inspect}")
72 75 end
73 76 end
74 77 end

0 comments on commit c981c2e

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