[ntp:questions] new driver development

Bruce Lilly bruce.lilly at gmail.com
Sun Apr 10 12:38:08 UTC 2011

On Sat, 09 Apr 2011 11:55:02 -0500, Hal Murray wrote:

> Is there any way to test to see if a mutex has been initialized?

One way is to call pthread_mutex_init and check for an EBUSY error return.
See the pthread_mutex_init man page for details.

One could also keep track of initialization status (and which process
initialized) in a variable in shared memory.  Either ignore locking
for setting that variable or try to deal with the chicken-or-egg issue.

I still advise using a semaphore in preference to a mutex, or
better still, avoid shared access entirely.

More information about the questions mailing list