Home
Support

Knowledge Base

BSPs and drivers
Community resources
Product documentation
Questions?
Contact us

Query on mutex deadlock issue
 
________________________________________________________________________

Applicable Environment
________________________________________________________________________
  • Topic: Query on mutex deadlock issue
  • SDP: 6.4.0
  • Target: Any supported target
________________________________________________________________________

Question
________________________________________________________________________

I have a functionality where two threads use a common resource. In a particular scenario in this, a thread locks a mutex and terminates when it is hit a signal while other thread continues to starve on this mutex indefinitely. I am trying to find a solution for this.

As a workaround, I have set a flag on locking the mutex and reset the flag when the mutex is unlocked. On the signal handler code, I have checked whether the flag is set. If so, I unlocked the mutex and exit from the thread. I think it is not a better solution.

I have read about robust mutex in which if the thread owning the mutex terminates with it locked, any other thread that is trying to lock it will unblock with error code EOWNERDEAD. By properly handling this error, the mutex deadlock problem can be solved. But I think it is not supported as per POSIX standard. Does QNX provide any posix extension to support similar type of mutex?

I searched through QNX APIs for mutex and didn't find any solution except the timed lock. But I am not sure if locking the mutex in every situation with a timeout is a better idea.

________________________________________________________________________

Recommendation
________________________________________________________________________

first use
http://www.qnx.com/developers/docs/6.4.1/neutrino/lib_ref/s/syncmutexevent.html
[Description:

The SyncMutexEvent() is a kernel call that attaches a specified event to a mutex pointed to by sync. You use SyncMutexRevive() to revive a DEAD mutex. Normally, a mutex will be placed in the DEAD state when the memory that was used to lock the mutex gets unmapped. One of the ways this may happen is when a process dies while holding the mutex in a shared memory. ]

Get the event and revive the mutex.

There is a seperate sample for SyncMutexRevive() here in our knowledgebase:


________________________________________________________________________
NOTE: This entry has been validated against the SDP version listed above. Use caution when considering this advice for any other SDP version. For supported releases, please reach out to QNX Technical Support if you have any questions/concerns.
________________________________________________________________________


Related Attachments
 None Found





Please contact us with your questions or concerns.