multithreading - Where should I put "exec this when jobs 1 .. n are done?" -


I have some parallel codes and a thread pool.

And I need to send 15 jobs, and when all 15 are completed , this particular task should be performed "Job 16".

You can only complete "Job 16"

Jobs 13, 14, 15.

Therefore , you should have a way to count. My question is, where is the responsibility related?

  • In the calling code : Use a static / global variable that will increase the end of every job of jobs 1-15 counter ++ When the counter == 15 , exec job 16
  • in the thread pool : execute Thunderpool "execute" when no work was submitted <
  • In the callback : (It is the responsibility to see that 1-15 jobs are completed, spin / sleep otherwise)

    You can also capture this behavior in your class, and raise an incident when your job is completed to trigger your 16th job queue:

      internal class parallelBatchRunner {public event EventHandler full = delegate}; Public Zero Run (list & jobs; task & gt; function) {int count = taskss.Count; Work. Foreike (T => {task completion torque = () => (T); if (interlocked. Acquisition (ref count) == 0} {complete (this, event.rg.pt);}} ; Threadpool QueueUserWorkItem (_ = & gt; Termination Task ());}); }}    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -