The reason error checking isn't necessary is because static
initialization cannot fail. In the most common implementations,
PTHREAD_MUTEX_INITIALIZER
will be something along the lines of
0
or {}
(depending on how pthread_mutex_t
is defined), to
ensure zero initialization, and the the various system calls
which use the pthread_mutex_t
are designed to treat a zero
initialized pthread_mutex_t
as if it had been initialized to
all default values, either because the type was designed
explicitly this way, or because the routines use lazy
initialization.
(Note that PTHREAD_MUTEX_INITIALIZER
cannot be anything along
the lines of __special_mutex_initializer()
, since it can be
used to initialize file scope static variables in C, and
C requires compile time constant expressions for the
initialization of static variables.)
EDIT:
For more information, you might want to read the rationale section of http://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_init.html. This describes several different possible implementations, and some of the trade-offs involved.