Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: pthread_* functionality currently in OS X



On Wednesday, March 27, 2002, at 03:03 PM, Conrad G T Yoder wrote:
At Wed, 27 Mar 2002 11:43:32 -0800, Matt Watson <email@hidden> wrote:

On Wednesday, March 27, 2002, at 11:29 AM, Conrad G T Yoder wrote:

  if (pthread_cond_wait(&condVar, &mutexVar) != 0) {
    CantHappen();
  }

What's the condition? You must call pthread_cond_wait() within a loop, with a predicate:

pthread_mutex_lock(&m);
while (condition == 0) {
	pthread_cond_wait(&c, &m);
}
/* Do some stuff */
pthread_mutex_unlock(&m);

All I am looking to do is have this thread sit and wait forever - no one will be signalling it ever. That's why there's no loop.

Not good enough. The pthread_cond_wait() call can (and does) return early. In particular, if the waiting thread is the target of a signal, pthread_cond_wait() returns. This is required behavior, because while running a signal handler the thread is not waiting on the condition and may miss a wakeup. So instead of that possibility, it returns to the caller and makes it determine whether "continued waiting" is the proper behavior or the condition was satisfied and it can return. You would just need a forever loop around your pthread_cond_wait() if you wanted it to wait forever.


--Jim
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.



References: 
 >Re: pthread_* functionality currently in OS X (From: Conrad G T Yoder <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.