Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, the problem seems to be in your ThreadPool#signal method. What may happen is:</p> <p>1 - All your worker are busy and you try to process a new job</p> <p>2 - line 90 gets a nil worker</p> <p>3 - a worker get freed and signals it, but the signal is lost as the ThreadPool is not waiting for it</p> <p>4 - you fall on line 95, waiting even though there is a free worker.</p> <p>The error here is that you can signal a free worker even when nobody is listening. This ThreadPool#signal method should be:</p> <pre><code>def signal @mutex.synchronize { @cv.signal } end </code></pre> <p>And the problem is the same in the Worker object. What might happen is:</p> <p>1 - The Worker just completed a job</p> <p>2 - It checks (line 17) if there is a job waiting: there isn't</p> <p>3 - The thread pool send a new job and signals it ... but the signal is lost</p> <p>4 - The worker wait for a signal, even though it is marked as busy</p> <p>You should put your initialize method as:</p> <pre><code>def initialize(callback) @mutex = Mutex.new @cv = ConditionVariable.new @callback = callback @mutex.synchronize {@running = true} @thread = Thread.new do @mutex.synchronize do while @running block = get_block if block @mutex.unlock block.call @mutex.lock reset_block # Signal the ThreadPool that this worker is ready for another job @callback.signal else # Wait for a new job @cv.wait(@mutex) end end end end end </code></pre> <p>Next, the Worker#get_block and Worker#reset_block methods should not be synchronized anymore. That way, you cannot have a block assigned to a worker between the test for a block and the wait for a signal.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload