Option 1 - Integrated
Since you have consecutive tasks, you can put these tasks in a chain and let the tasks themselves resend the thread pool after they are completed. Suppose we have a list of tasks:
[Task1, ..., Task6]
as in your example. We have a sequential dependency, such that [Task3, Task4, Task6] is a chain of dependencies. Now we do the work (Erlang pseudo-code):
Task4Job = fun() -> Task4(), % Exec the Task4 job push_job(Task6Job) end. Task3Job = fun() -> Task3(), % Execute the Task3 Job push_job(Task4Job) end. push_job(Task3Job).
That is, we change the task Task3 , transferring it to the task, which as a continuation pushes the next task in the queue to the thread pool. There are strong similarities with the general style of passing continuation, which is also found in systems like Node.js or Pythons Twisted .
Summarizing, you create a system in which you can define task chains that can defer continue working and resend further work.
Option 2 - Simple
Why are we even worried about job sharing? I mean, since they are sequentially dependent, executing all of them in the same thread will not be faster or slower than taking this chain and distributing it across multiple threads. Assuming a "sufficient" workload, any thread will always work anyway, so just linking tasks together is probably the easiest way:
Task = fun() -> Task3(), Task4(), Task6() % Just build a new job, executing them in the order desired end, push_job(Task).
It is very easy to do such things if you have the functions of first-class citizens so that you can create them in your own language as you wish, for example, any programming language, Python, Ruby-blocks - etc.
I do not really like the idea of creating a queue or continuation stack, as in "Option 1", although I would definitely go with the second option. At Erlang, we even have programs called jobs written by Erlang Solutions and released as Open Source. jobs designed to run and load, governing jobs like these. I would probably combine option 2 with assignments if I solve this problem.