15.1 The three multithreading APIs
Three multithreading APIs are available to Gnulib users:
- POSIX multithreading,
- ISO C multithreading,
- Gnulib multithreading.
They are supported on all platforms that have multithreading in one form or
the other. Currently, these are all platforms supported by Gnulib, except
for Minix.
The main differences are:
- The exit code of a thread is a pointer in the POSIX and Gnulib APIs, but
only an
int
in the ISO C API.
- The POSIX API has additional facilities for detaching threads, setting the
priority of a thread, assigning a thread to a certain set of processors,
and much more.
- In the POSIX and ISO C APIs, most functions have a return code, and you
are supposed to check the return code; even locking and unlocking a lock
can fail. In the Gnulib API, many functions don’t have a return code; if
they cannot complete, the program aborts. This sounds harsh, but such
aborts have not been reported in 12 years.
- In the ISO C API, the initialization of a statically allocated lock is
clumsy: You have to initialize it through a once-only function.