Does PTHREAD_MUTEX_INITIALIZER work?

Dag-ErlingSmørgrav des at des.no
Thu Mar 11 11:28:59 PST 2004


Anders Torger <torger at ludd.luth.se> writes:
> PTHREAD_MUTEX_INITIALIZER is defined as NULL in 5.2.1 too. I shall
> test the software on that platform later though. However, it would
> be nice if someone could explain this NULL thing

Our pthread_mutex_t is a pointer type, and the pthread_mutex_*
functions will automatically create a new mutex with default
attributes if the specified mutex is NULL (remember that it is passed
by reference, so they can replace NULL with a pointer to the new mutex
structure)

>                                                  (it is not NULL on
> other pthread implementations I have looked at).

Other implementations may define pthread_mutex_t as a struct, in which
case PTHREAD_MUTEX_INITIALIZER corresponds to an initialized, unlocked
mutex with default attributes.  The advantage of this is that mutexes
can be used in places where malloc() calls are prohibited (such as in
signal handlers and within malloc() itself).  On the other hand, you
can't change the size of that struct without breaking binary
compatibility.

DES
-- 
Dag-Erling Smørgrav - des at des.no


More information about the freebsd-threads mailing list