nash@vi.ri.cmu.edu (Richard Nash) (07/24/90)
Is there any way to kill a thread in mach? In my case I want to timeout if the thread doesn't complete it's task quickly and kill it. I am using the Cthreads package provided by NeXT because its easy. Do I have to go to using the mach system calls to do this? -- Richard V. Nash nash@vi.ri.cmu.edu -- Richard V. Nash nash@vi.ri.cmu.edu
joerg@mcs.anl.gov (Joerg) (07/25/90)
To kill a thread, you might do something like this: cthread_t killMe; thread_terminate(cthread_thread(killMe)); Be sure you've anticipated all the potential side-effects of suddenly stopping whatever the killMe thread was doing. David S. Joerg Internet : joe@alliant.mcs.anl.gov (until September)
avie@wb1.cs.cmu.edu (Avadis Tevanian) (08/04/90)
In article <1990Jul24.230238.12159@mcs.anl.gov> joerg@mcs.anl.gov (Joerg) writes: >cthread_t killMe; > >thread_terminate(cthread_thread(killMe)); This will almost always not be the right thing to do. The problem here is that you end up terminating the thread out from under the C-Thread package which is not a good thing. Your best bet is to structure your application such that it can use cthread_exit. It is true that this is sometimes difficult within the confines of C-Threads. C-Threads errs on the side of simplicity, but we should probably add a cthread_terminate that can terminate other C-Threads. I will point out that using such a call would also be very dangerous as the cthread you are going to terminate could very well hold locks or other type of important state. One other thing about cthread_thread(). It does give you a mechanism to figure out which Mach thread is underlying a specific C-Thread, but you must be very careful when using Mach thread calls on this thread. You may end up changing things that will confuse the C-Threads package. -- Avadis Tevanian, Jr. (Avie) Manager, System Software NeXT, Inc. avie@NeXT.COM