Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

Threading Model Poll

Threading Model defines the way a user thread maps to a kernel scheduled entity, either a process or a kernel thread. There are two leading models 1:1 (one to one) and M:N.

In 1:1 approach, each user thread is mapped to a kernel scheduled entity. Thread creation, termination, synchronization and scheduling all end up as kernel activities.
The strength is that the thread scheduling is simple. Application software is easy to debug.
The weakness is the management overhead to maintain all the threads information, the time spent on ring switches (going from user to kernel space) for major thread operations and also the potential bottleneck in kernel scheduler. Many kernel threads increase the chances of context switch.
Win32 Threads, LinuxThread, and NPTL adopts 1:1 Model.

In M:N approach, user and kernel threads do not have to be in a fixed correlation, ie Many user threads running on aNy number of kernel threads. Thread creation, termination and synchronization could simply be user space operations. Thread scheduling is accomplished as a joint effort between user space scheduler and kernel level scheduler.
The strength is the flexibility. The number of user threads could be optimized for each application workload, and number of kernel threads optimized for number of processors or availability of HT. Another area of strength is the scalability. Large amount of user threads do not necessarily translate into huge kernel data structures, which reduces the chance of context switching. Thread creation, termination and some synchronization happens on the user space.
The weakness is that the synchronization involves the intact cooperation between kernel and user scheduler and thus complex and difficult to implement. For example, a simple mechanism of scheduling activation, which requires user level scheduler provide the hints to the kernel and the kernel scheduler notifies the result to the user scheduler, would necessitate passing a substantial amount kernel information from kernel to user space.
Both Window Fibers and IBM NGPT for Linux implements M:N model, do did the previous Solaris? version.

0 Kudos
0 Replies