Issue
In man page for interface like pthread_mutex_init
,
int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);
It says "If attr is NULL, the default mutex attributes are used...", and the default mutex attributes
are mentioned many times, and it is also mentioned in the book The Linux Programming Interface
, but it is never explained in detail anywhere, I googled and no result.
There is one post what is the "attribute" of a pthread mutex?, and it mentioned "Usually, the default is a sensible set of attributes but it may vary between platforms", but it is not what I want, I want more details.
So, what is exactly the default mutex attributes
?
Solution
pthread_mutexattr_t
is an opaque type (you never modify it directly) that's accessed via various pthread_mutexattr_get*()/set*()
functions. Unless the documentation for those functions specify a default, then the default is up to the implementation, and you can't rely on a particular value.
You could follow the links to the various pthread_mutexattr_get*()
functions in POSIX.1-2008 here and look for default values (which also apply when you pass NULL
for the attributes). Here's some choice quotes:
pthread_mutexattr_getprotocol():
The default value of the attribute shall be PTHREAD_PRIO_NONE.
The default value of the type attribute is PTHREAD_MUTEX_DEFAULT.
pthread_mutexattr_getpshared():
The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE.
pthread_mutexattr_getrobust():
PTHREAD_MUTEX_STALLED ... This is the default value.
The non-type attributes are kinda obscure though.
Answered By - Ulfalizer Answer Checked By - Marie Seifert (WPSolving Admin)