Date: Thu, 11 Mar 2004 20:28:46 +0100 From: des@des.no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=) To: Anders Torger <torger@ludd.luth.se> Cc: freebsd-threads@freebsd.org Subject: Re: Does PTHREAD_MUTEX_INITIALIZER work? Message-ID: <xzpsmgf5gk1.fsf@dwp.des.no> In-Reply-To: <200403111616.15668.torger@ludd.luth.se> (Anders Torger's message of "Thu, 11 Mar 2004 16:16:15 %2B0100") References: <200403111459.11287.torger@ludd.luth.se> <40507287.1040203@he.iki.fi> <200403111616.15668.torger@ludd.luth.se>
next in thread | previous in thread | raw e-mail | index | archive | help
Anders Torger <torger@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 --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?xzpsmgf5gk1.fsf>