Neil Schellenberger(deleted)
|
Re: problem with pthread_kill
|
Neil Schellenberger(deleted)
02/17/2011 7:21 PM
post83298
|
Re: problem with pthread_kill
Keep in mind that POSIX says:
"Note that pthread_kill() only causes the signal to be handled
in the context of the given thread; the signal action
(termination or stopping) affects the process as a whole."
Since you haven't installed a handler for SIGINT, while the signal is
delivered to thread one, the default behaviour applies (process
termination).
On Thu, 2011-02-17 at 19:06 -0500, Mitchell Schoenbrun wrote:
> I'm finding unexpected behavior with pthread_kill(). If I substitute
> pthread_abort() there is no problem. The following program
> demonstrates the problem under 6.3.2 and 6.5. I would expect after
> killing thread1, I would continue to see output from thread2 and from
> the main thread when it finishes. Instead, the process almost
> immediately exits.
>
> I humbly assume that I'm doing something wrong, but if I'm not, this
> would seem to be a serious bug.
>
> Thanks
>
>
> #include <libc.h>
> pthread_t thread1;
> pthread_t thread2;
> void *thread1_function(void *arg)
> {
> while(1)
> {
> fprintf(stderr,"Thread 1 Alive\n");
> sleep(1);
> }
> }
> void *thread2_function(void *arg)
> {
> while(1)
> {
> fprintf(stderr,"Thread 2 Alive\n");
> sleep(1);
> }
> }
> int main()
> {
> pthread_create(&thread1,NULL,thread1_function,0);
> pthread_create(&thread2,NULL,thread2_function,0);
> fprintf(stderr,"Thread1 %d, Thread2 %d\n",thread1,thread2);
> sleep(4);
> fprintf(stderr,"Killing Thread\n");
> pthread_kill(thread1,SIGINT);
> fprintf(stderr,"Thread Killed\n");
> sleep(10);
> fprintf(stderr,"Done\n");
> }
>
>
>
>
> _______________________________________________
>
> OSTech
> http://community.qnx.com/sf/go/post83297
>
>
>
|
|
|