On Tue, Mar 26, 2002 6:00 PM, Conrad G T Yoder <mailto:email@hidden>
wrote:
>I am porting a (hairy) Solaris app to OS X which makes heavy use of the
>pthread libraries (blocking, unblocking, cond vars, mutexes, etc.). When
>I try to have the main thread sleep somehow (I have tried sleep(),
sem_wait(),
>pthread_cond_wait()) after spawning and starting all the other pthreads,
>the program just pegs the CPU when the main thread gets to this call.
This is a problem I was seeing in a similar situation, a main thread kicks
off many other threads, then the main thread suspends. Until I got things
fixed, I was seeing the "pegs the CPU" problem also. My solution, however,
sounds like one you've tried already. Just in case it's useful...
My app has an ExSignal class that it uses for semaphore-style services. On
other platforms, ExSignal is implemented using unnamed semaphores
(implemented by sem_init and sem_destroy)--these are not supported on OSX.
I ended up using pthread_mutex and pthread_cond to implement ExSignal (as
Jim Magee <email@hidden> suggested), and this works very well (thanks,
Jim).
At this point, I get the main-thread-suspend service by (in effect) doing:
pthread_mutex_lock( someMutex );
pthread_cond_wait(someCond, someMutex);
(actually, the app uses:
ExSignal temp;
temp.WaitForSignal();
and WaitForSignal does the mutex_lock and cond_wait.)
Since nothing ever signals 'someCond' (although the cond_wait can be
interrupted by the system), the thread waits practically forever as
desired.
Hope this helps,
Lindsey Spratt.
Digital Archaeology Corporation, division of Delano Technology Corporation.
_______________________________________________
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.