newsgnulib - GNU portability library - News

 
 

Gnulib supports portable multithreading

Item posted by Bruno Haible <haible> on Wed 30 Dec 2020 03:10:08 PM UTC.

There are three main motivations for using multiple threads in a program:


For the first case, the OpenMP standard and its implementation in GCC, libgomp, provide all you need. It uses multiple threads under the hood. Use the Autoconf macro AC_OPENMP for portability.

For the other cases, or when you want to control the threads yourself, you'll need to choose a multithreading API. Two such APIs are available across all platforms, through Gnulib:


POSIX multithreading and ISO C multithreading are similar. ISO C multithreading contains only the essential APIs, whereas POSIX multithreading has more features. For example, while both have locks/mutexes, only POSIX has spin-locks. And when creating a thread, only POSIX allows to specify thread attributes, such as its stack size or its scheduling priority. Also, lock initialization is straightforward in POSIX, but clumsy in ISO C.

Without Gnulib, none of these two APIs can be used across platforms:


With Gnulib, you can use either of these APIs across platforms:


My personal recommendation is:


Back to the top

Powered by Savane 3.13-02a9.
Corresponding source code