What are the “default mutex attributes” of pthread_mutex**
In the man pages for
interfaces such as pthread_mutex_init
int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr);
It says “If attr is NULL, use the default mutex attribute…”, the default mutex attribute is mentioned several times, it is also mentioned in
The Linux Programming Interface book, but never
explained in detail anywhere, I googled it without results.
There is a
post what is the “attribute” of a pthread mutex? , which mentions “usually, the default is a reasonable set of properties, but it may vary from platform to platform”, but that’s not what I want, I want more details.
So, what exactly are
the default mutex properties?
pthread_mutexattr_t is an opaque type (you never modify it directly) and is accessible through various pthread_mutexattr_get*()
/set*() functions. Unless the documentation for those functions specifies a default value, the default value depends on the implementation, and you cannot rely on a specific value.
You can click POSIX.1-2008 various
pthread_mutexattr_get*() here Links to functions. and look for the default value (also applies when you pass
NULL for the property). Here are some selection offers:
The default value of the attribute shall be PTHREAD_PRIO_NONE.
The default value of the type attribute is PTHREAD_MUTEX_DEFAULT.
The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE.
PTHREAD_MUTEX_STALLED … This is the default value.
Although the non-type property is a bit obscure.