Note that there are some explanatory texts on larger screens.

plurals
  1. POThread Pool : how to spawn a child task from a running task?
    text
    copied!<p>A simple thread pool with a global shared queue of tasks (functors).</p> <p>Each worker (thread) will pick up one task from the worker, and execute it. It wont execute the next task, until this one is finished.</p> <p>Lets imagine a big task that needs to spawn child tasks to produce some data, and then continue with evaluation (for example, to sort a big array before save to disk).</p> <p>pseudo code of the task code:</p> <pre><code> do some stuff generate a list of child tasks threadpool.spawn (child tasks) wait until they were executed continue my task </code></pre> <p>The problem is that the worker will dead lock, because the task is waiting for the child task, and the thread pool is waiting for the parent task to end, before running the child one.</p> <p>One idea is to run the child task inside the spawn code:</p> <p>threadpool.spawn pseudo code:</p> <pre><code> threadpool.push (tasks) while (not all incoming task were executed) t = threadpool.pop() t.run() return (and continue executing parent task) </code></pre> <p>but, how can I know that all the task were executed , in an efficient way?</p> <p>Another idea is to split the parent task.. something like this:</p> <p>task pseudo code:</p> <pre><code> l = generate a list of child tasks threadpool.push ( l , high priority ) t = create a task to work with generated data threadpool.push (t , lo priority ) </code></pre> <p>But i found this quite intrusive...</p> <p>any opinions?</p> <p>pd. merry christmas! pd2. edited some bad names</p>
 

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