Next: , Previous: , Up: Multithreading   [Contents][Index]


15.2 Choosing the right multithreading API

Here are guidelines for determining which multithreading API is best for your code.

In programs that use advanced POSIX APIs, such as spin locks, detached threads (pthread_detach), signal blocking (pthread_sigmask), priorities (pthread_setschedparam), processor affinity (pthread_setaffinity_np), it is best to use the POSIX API. This is because you cannot convert an ISO C thrd_t or a Gnulib gl_thread_t to a POSIX pthread_t.

In code that is shared with glibc, it is best to use the POSIX API as well.

In libraries, it is best to use the Gnulib API. This is because it gives the person who builds the library an option ‘--enable-threads={isoc,posix,windows}’, that determines on which native multithreading API of the platform to rely. In other words, with this choice, you can minimize the amount of glue code that your library needs to contain.

In the other cases, the POSIX API and the Gnulib API are equally well suited.

The ISO C API is never the best choice, as of this writing (2020).