Linked by Elad Lahav on Thu 18th Feb 2016 19:27 UTC
QNX

A mutex is a common type of lock used to serialize concurrent access by multiple threads to shared resources. While support for POSIX mutexes in the QNX Neutrino Realtime OS dates back to the early days of the system, this area of the code has seen considerable changes in the last couple of years.

Permalink for comment 625015
To read all comments associated with this story, please click here.
RE[3]: Mutex behavior
by elahav on Fri 19th Feb 2016 16:13 UTC in reply to "RE[2]: Mutex behavior"
elahav
Member since:
2009-05-28


sem_init(&sem, 1);
...
sem_wait(sem); // lock
// equivalent to mutex
sem_post(sem); // unlock (even in new thread)


This is not equivalent to a mutex. While a count-1 semaphore behaves similarly to a mutex, there are subtle, yet important, differences, resulting from a semaphore not having an owner:
1. Any thread can signal the semaphore, leading to a loss of mutual exclusion (which will go unnoticed until data corruption is observed).
2. No way to avoid priority inversion.

You may not care about these problems in this particular case, but it is important to understand the semaphore/mutex divide.

Reply Parent Score: 1