OpenQNX :: The QNX Community Portal

Sep 08, 2008 - 03:07 PM
Google
  Web openqnx.com   
     Create an account Home · Submit News · QNX Forums · QNX Download · Search   
_
Main Menu
Who's Online
There are 43 unlogged users and 1 registered user online.

You can log-in or register for a user account here.

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
yicheng
Post subject: Linux "complete()" and "wait_for_completion_t  PostPosted: 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
 
 View user's profile Send private message  
Reply with quote Back to top
davepage
Post subject: RE: Linux "complete()" and "wait_for_completi  PostPosted: Jan 13, 2008 - 03:52 AM
New Member


Joined: Oct 29, 2005
Posts: 8

See:
http://lwn.net/Articles/23993/
http://lwn.net/Articles/120614/

Looks like sem_timedwait() might be a good fit.
 
 View user's profile Send private message  
Reply with quote Back to top
rgallen
Post subject: Re: RE: Linux "complete()" and "wait_for_comp  PostPosted: Jan 14, 2008 - 07:13 PM
QNX Master


Joined: Jul 11, 2002
Posts: 600

davepage wrote:
See:
http://lwn.net/Articles/23993/
http://lwn.net/Articles/120614/

Looks like sem_timedwait() might be a good fit.


Nope. Semaphores should never be used in a real-time system (they are not priority conveying).

Use pthread_sleepon_timedwait().
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
yicheng
Post subject: Re: RE: Linux "complete()" and "wait_for_comp  PostPosted: 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?
 
 View user's profile Send private message  
Reply with quote Back to top
rgallen
Post subject: Re: RE: Linux "complete()" and "wait_for_comp  PostPosted: 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...
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
yicheng
Post subject: Re: RE: Linux "complete()" and "wait_for_comp  PostPosted: 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?
 
 View user's profile Send private message  
Reply with quote Back to top
rgallen
Post subject: Re: RE: Linux "complete()" and "wait_for_comp  PostPosted: 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.
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2007 The PNphpBB Group
Credits
All logos and trademarks in this site are property of their respective owners. The comments are property of their posters.
Powered by OpenQNX: The QNX Community Portal Site
QNX and the QNX logo are registered trademarks of QNX Software Systems.