Subj : Re: Answer :Re: Answer David Schwartz 's question To : comp.programming.threads From : David Schwartz Date : Tue Apr 05 2005 02:31 am "ymjzxw" wrote in message news:74d50203.0504042314.6d693ab4@posting.google.com... > Oh,that is to say when in the middle of 'malloc', if stopped it,the > thread may not allocate the memory. > Or is there anything else? Please give me more infomation in detail. > Thank you very much, I am a newbie of NPTL:-) There are two possible cases: 1) You don't have the cooperation of the other thread, the thread might be doing anything at all, and you can't do anything safely while you've stopped it. 2) You do have the cooperation of the other thread and you have control over what the other thread is doing. In this case, you can do anything safely. However, if you had the cooperation of the the other thread, it's unlikely you would have asked how to stop it, since it would be obvious, you code the other thread to call 'usleep' or 'pthread_cond_wait' or whatever. The textbook answer to the question "how do I stop all other thread" is: There is probably a better way to do whatever it is you're trying to do. But the answer is that without the other thread's cooperation, it is impossible to do safely. With their cooperation, any method you like will work just fine. (For example, you can use condition variables and mutexes to coordinate the other threads blocking at a safe point until released.) DS .