When Task-Based Programming Is Inappropriate

Using the task scheduler is usually the best approach to threading for performance, but there are cases when the built-in task scheduler is not the most appropriate solution. The task scheduler is intended for high-performance algorithms composed of nonblocking tasks. It still works if the tasks block occasionally. However, if threads block frequently, there is a performance loss when using the task scheduler because the processor is not doing any work while the task is blocked.

Blocking typically occurs while waiting for I/O or mutexes for long periods. If threads hold mutexes for long periods, your code is not likely to perform well anyway, no matter how many threads it has. If you have blocking tasks, it is best to use full-blown threads for those. The task scheduler is designed so that you can safely mix your own threads with Threading Building Blocks tasks.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.105.239