kill a thread from another thread but the pgm should continue working!!

kill a thread from another thread but the pgm should continue working!!

Post by sandeep_ka » Wed, 03 Nov 2004 23:55:52


Hi,

I have written a multithreaded pgm which is working quite fine.Along
with main func i have used func1() executed from thread1 and a func2()
executed from thread2. I hv to kill the thread2 from func1()
depending on requirements in such a way that the program shouldnot
stop and it should continue working. Only the specified thread
identified by its id should be killed and the program should go on
running.I am using thr_kill(). I tried using a lot of signals but
those that really killed the thread made the process killed too and
program stopped running meaning i got the dollar$ prompt back. I am
using Sun OS 5.8. Also killing the threads doesnt reduce the
corresponding LWPS checked using
prstat -p pid command. Plz anyone can help me reg this.

any help will be highly appreciated.

thanks.

K.S.
 
 
 

kill a thread from another thread but the pgm should continue working!!

Post by Joe Seig » Thu, 04 Nov 2004 23:12:26


Uncaught signals kill the process no matter what thread receives the
signal. Changing the behavior to just terminate the thread would
potentially leave shared resources in an undefined state which most
responsible programmers would view as a Bad Thing.

You should use pthread_cancel or normal pthread signaling via condvars
to do what you want.

Joe Seigh