High Coding Overhead

Raw threads, such as POSIX threads (pthreads) or Windows threads, expose the control of parallelism at its lowest level. They represent the assembly languages of parallelism. As such, they offer maximum flexibility at a high cost.

When using raw threads, programmers find basic work to be difficult and tedious to write correctly and efficiently. Code often becomes very dependent on the particular threading facilities of an operating system. Raw thread-level programming is too low-level to be intuitive and seldom results in code designed for scalable performance. Furthermore, the programming model does not encourage nested parallelism, which turns out to be very important.

With thread-based programming, you are forced to think at the low level of physical threads to get good efficiency because you want to maintain one logical thread per physical thread—and make sure that the logical thread is not blocked for long periods of time—to avoid undersubscription or oversubscription. You also have to deal with the relatively coarse grain of threads.

The main advantage of using tasks instead of threads is that they let you think at a higher, task-based level. You can concentrate on dependencies among tasks and leave efficient scheduling to the scheduler.

Get Intel Threading Building Blocks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.