Subj : Re: How to manage time-slicing in Pthreads programs? To : comp.programming.threads From : David Schwartz Date : Sat Feb 19 2005 01:50 pm "D'artagnan" wrote in message news:1108847304.376850.217850@g14g2000cwa.googlegroups.com... >I have a program spawning only two threads, say A and B. At some point, > I want to put thread A into sleep and have thread B take the whole time > slot. Thead A should wake up after a certain period of time or on some > signals sent by Thread B. Put this in another way, I want to stop > time-slicing between the two threads and resume it at any time. I am > using POSIX threads on Linux 2.4. I don't have NPTL. Any suggestions? > If I want to port the same code to Tru64, are there any differences? > Thanks a lot. Here's the textbook answer to this question: With the cooperation of thread A, any method at all will work. Thread A can put itself to sleep or block on a synchronization function. It can check a shared variable (with appropriate mutex protection) to tell when the other thread wants it to sleep. Without the cooperation of thread A, no method will work safely. You always run the risk of putting thread A to sleep while it holds a mutex thread B will need later, resulting in deadlock. There are other risks as well. DS .