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 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);


The signalling thread would do something like this:

pthread_mutex_lock(&m);
condition = 1;
pthread_cond_signal(&cond);
pthread_mutex_unlock(&m);

The cond_signal can come outside the lock, but it's recommended to come inside the lock for predictive scheduling behavior...


How are the mutexes and conditions initialized? If you attach in gdb,
where is it spinning? This could be due to memory corruption, where one
of the internal pthread spin locks has been set and will never unlock.

When I attach with gdb and then interrupt, it is always in semaphore_wait_signal_trap() - from `bt`:

#0 0x7003f4c8 in semaphore_wait_signal_trap ()
#1 0x7003f2c8 in _pthread_cond_wait ()
#2 0x0048b734 in os_StartKernel (memoryAddres=0x5690a08 "", memorySize=104850936, systemStackSize=4096, interruptStackSize=0) at foo.c:744
#3 0x00489df4 in os_StartTheWorld () at bar.c:477
#4 0x00002a2c in main (argc=2, argv=0xbffff610) at main.c:388
#5 0x00002340 in _start ()
#6 0x00002170 in start ()

Why do you say it's spinning? This is normal blocking behavior. Is the app taking up CPU? What are the backtraces of the other threads?


matt.
_______________________________________________
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.