|Do you know where your variables are?|
Re^3: How can I force thread switching?by BrowserUk (Pope)
|on Sep 29, 2013 at 19:15 UTC||Need Help??|
one of the threads is silently terminated (without intentional error injection) and I can't find why.
Your first thread to run will always terminate immediately because you are pushing a job id of zero:
Which when it is received:
Test false and terminates the loop.
Aside from that, your code is very confused. I have no idea what syncIdle is meant to be doing, and removing it, along with various other chunks of code that seem to serve no good purpose, I got to this which runs perfectly:
That said, limiting your queue to 4 elements to feed 4 threads means that your threads are running in lock-step, which pretty much defeats the purpose of using a queue.
And using Thread::Semaphore as the mechanism for limiting the size of the queue is like hiring the Pinkerton's to manage the queue for the bathroom in the mornings. Not just overkill, but by forcing lock-step (synchronising your threads), throws away much of the gain from asynchronous processing.
Here's how I would write the same program:
You can get threads::Q (my own, efficient, self-limiting queue implementation) from here.
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.