Code example – querying the default thread attributes

For now, a useful experiment would be to query the default attributes of a newly born thread whose attribute structure is specified as NULL (default). How? pthread_default_getattr_np(3) will do the trick (note though, that again, the _np suffix implies that it's a Linux-only, non-portable API):

#define _GNU_SOURCE /* See feature_test_macros(7) */#include <pthread.h>int pthread_getattr_default_np(pthread_attr_t *attr);

Interestingly, as this function depends on the _GNU_SOURCE macro being defined, we must first define the macro (early in the source); otherwise, the compile triggers warnings and possibly fails. (In our code, we thus use #include "../common.h" first as our common.h header ...

Get Hands-On System Programming with Linux 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.