| Author |
Message |
|
|
Post subject: Linux "complete()" and "wait_for_completion_t
Posted: Jan 07, 2008 - 07:17 PM
|
|
Active Member
Joined: Nov 28, 2005
Posts: 59
|
|
Hi Folks,
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?
Thanks!
Yicheng |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: Linux "complete()" and "wait_for_completi
Posted: Jan 13, 2008 - 03:52 AM
|
|
New Member
Joined: Oct 29, 2005
Posts: 8
|
|
|
|
|
 |
|
|
Post subject: Re: RE: Linux "complete()" and "wait_for_comp
Posted: Jan 14, 2008 - 07:13 PM
|
|
QNX Master
Joined: Jul 11, 2002
Posts: 600
|
|
|
davepage wrote:
Nope. Semaphores should never be used in a real-time system (they are not priority conveying).
Use pthread_sleepon_timedwait(). |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: RE: Linux "complete()" and "wait_for_comp
Posted: Jan 15, 2008 - 06:00 AM
|
|
Active Member
Joined: Nov 28, 2005
Posts: 59
|
|
|
rgallen wrote:
Nope. Semaphores should never be used in a real-time system (they are not priority conveying).
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? |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: RE: Linux "complete()" and "wait_for_comp
Posted: Jan 16, 2008 - 01:48 AM
|
|
QNX Master
Joined: Jul 11, 2002
Posts: 600
|
|
|
yicheng wrote:
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?
Yes.
yicheng wrote:
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... |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: RE: Linux "complete()" and "wait_for_comp
Posted: Jan 16, 2008 - 06:42 AM
|
|
Active Member
Joined: Nov 28, 2005
Posts: 59
|
|
|
rgallen wrote:
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...
Then what synchronization primitive should be used to replace the "counting semaphore", which has positive value more than 1? |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: RE: Linux "complete()" and "wait_for_comp
Posted: Jan 17, 2008 - 12:53 AM
|
|
QNX Master
Joined: Jul 11, 2002
Posts: 600
|
|
|
yicheng wrote:
rgallen wrote:
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...
Then what synchronization primitive should be used to replace the "counting semaphore", which has positive value more than 1?
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. |
|
|
| |
|
|
|
 |
|
|