I have a situation that I don't know how to solve.
We have 1 Worker_Manager and a fixed number of Workers.
The Workers are created inside the Worker_Manager using fork{ ... }
Each worker should communicate to the Worker_Manager when it finalizes its task.
The Worker_Manager should stop the EM and BrB service when all workers has contacted the Worker_manager.
Currently I have a counter in Worker_Manager. Everytime a worker finalises y call a method on the Worker_Manager that increments that counter. When the counter reaches the desired number (number of workers) then it stops the EM and Brb::Service.
The problem is that there is a death_lock in this design.
If I say that the method call to increment the counter at Worker_Manager is _block, then when the services are stop there won't be a return, so the worker is left waiting.
If it is not a _block, then some thing weird happens – even if I put a sleep(4) – and the Work_Manager blocks too.
I don't know what more to try. Do you see anything wrong?
You can reproduce all this with:
rspec spec/worker_manager/WorkerManager_spec.rb -f d -c
Thank you.
Code:
http://github.com/Nerian/DPovray/tree/WorkerManager
See worker_manager.rb , method render_scene
See worker.rb , method start_your_work