I have been trying to learn more details on CLR 4.0. and the ThreadPool and the different strategies that Microsoft recommended. I consider myself fairly up-to-date on a lot of these topics, and use threading and concurrent code on a daily basis.
I have been goign back through the Parallel Patterns and Practices again recently, and am a bit caught on the Decentralized Scheduling Techniques section which gives a brief overview of 'Work Stealing' and local vs global thread queues.
The questions I have are:
1) Is work stealing opt-in or opt-out? Same for using local thread queues? Or does this happen by default with CLR 4.0?
2) Do we have control over whether we are using local or global thread queues? If so, through what API calls?
You have no control over either. That is describing how the default thread scheduler schedules it's tasks. That is simply how it works. You can create your own TaskScheduler entirely, and write your own scheduler from scratch, and you can also use
TaskCreationOptions
to provide some hints to the scheduler (which, if it wants, it's free to ignore) but none of those options allow you to specify which of those queues a task goes into.The primary point of the Task model is that you don't need to worry about such details; the intent is that the work can be scheduled by any of the worker threads, in any order, and that you're allowing the framework scheduler to do it's best to optimize the work. Adding constants makes it harder for it to do that effectively. As previously mentioned, you can use a custom task scheduler if you require a radically different algorithm for scheduling tasks.