Attach an event to a mutex
#include <sys/neutrino.h> int SyncMutexEvent( sync_t * sync, struct sigevent * event ); int SyncMutexEvent_r( sync_t * sync, struct sigevent * event );
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The SyncMutexEvent() and SyncMutexEvent_r() kernel calls attach the specified event to a mutex pointed to by sync. This event is delivered when the mutex enters the DEAD state, which happens when a process holding the mutex removes its last mapping of the mutex without unlocking it (including when the process dies while holding the mutex in shared memory).
|This is likely caused by a bug in the process. Although the OS provides a way to detect this situation and revive the mutex, the data that the mutex is protecting might be in an inconsistent state.|
SyncMutexEvent() and SyncMutexEvent_r() are similar, except for the way they indicate errors. See the Returns section for details.
When you're notified that a mutex has been put into the DEAD state, you can revive it with SyncMutexRevive().
If you call SyncMutexEvent() with a NULL event, the function deletes any existing event registration.
Here's how you might use a mutex in shared memory between threads in two or more processes and attempt to deal with the death of one of the processes while it's holding the mutex.
If it's the shared memory's owner/manager process that died, then there's no event delivered, and the mutex is marked as DESTROYED; you can use procmgr_guardian() to try to handle this case. If there's no event registered, the mutex is marked as DESTROYED. In both these cases, the kernel sends a SIGDEADLK signal to all threads that are waiting, without a timeout, on the mutex. If these threads have blocked SIGDEADLK, they're made READY, as are threads that are waiting on the mutex, but with a timeout.
If you call pthread_mutex_lock():
The only difference between these functions is the way they indicate errors:
sigevent, SyncCondvarSignal(), SyncCondvarWait(), SyncDestroy(), SyncMutexLock(), SyncMutexRevive(), SyncMutexUnlock()