I am looking for a TaskScheduler that:
- Allows me to define a number of dedicated threads (e.g. 8) - a standard
LimitedConcurrencyLevelTaskScheduler(uses threadpool threads) orWorkStealingTaskSchedulerdo this. - Allows me to create sub-TaskSchedulers that are fully ordered but schedules the tasks on the dedicated threads of the parent scheduler.
At the moment we use TaskScheduler.Default for the general pool (at the mercy of the threadpool growth algorithm etc) and new OrderedTaskScheduler() whenever we want to order tasks. I want to keep this behavior but limit both requirements to my own pool of dedicated threads.
QueuedTaskScheduler seems to get pretty close. I thought the QueuedTaskScheduler.ActivateNewQueue() method, which returns a child TaskScheduler would execute tasks IN ORDER on the pool of workers from the parent but that doesn't seem to be the case. The child TaskSchedulers seem to have the same level of parallelization as the parent.
I don't necessarily want the child taskscheduler tasks to be prioritised over the parent taskscheduler tasks (although it might be a nice feature in the future).
I have seen a related question here: Limited concurrency level task scheduler (with task priority) handling wrapped tasks but my requirements do not need to handle async tasks (all my enqueued tasks are completely synchronous from start to end, with no continuations).
I assume by "fully ordered" you also mean "one at a time".
In that case, I believe there's a built-in solution that should do quite well:
ConcurrentExclusiveSchedulerPair.Your "parent" scheduler would be a concurrent scheduler:
And the "child" schedulers would be an exclusive scheduler that uses the concurrent scheduler underneath: