I’m porting a Linux driver to QNX. The driver uses “complete(struct completion *x)” and “wait_for_completion_timeout(struct completion *x, unsigned long timeout)” kernel call in Linux. What is the best way to implement these functions in QNX? Can I just use semaphore to implement block waiting?
So if a higher priority thread waits for a semaphore which has already been locked by a lower priority thread, the lower one won’t be promoted to the same priority level as the higher one, is it the meaning of priority conveying? Can I use semaphore if the two threads have the same priority?
Not unless you have a really good reason; and absolutely never in any program that ever makes a blocking call which could result in an elevated priority (since the presence of the semaphore would break the “promise” made by your thread when it “accepted” that priority, that it would complete all work at that elevated priority - a promise it can’t keep if it uses a semaphore).
Unless you enjoy arduous debugging sessions, I’d stay as far away from semaphores as I would from a leaky flask full of ebola virus…
None. There is nothing in Posix threads that replaces the counting semaphore, precisely because priority inheritance can’t operate with a model that has no identifiable owner.
Any architecture that uses a counting semaphore structure, can be implemented with a struct that contains a mutex, count and condvar.