bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

pthread_setcancelstate and sigabrt


From: Ken Teh
Subject: pthread_setcancelstate and sigabrt
Date: Fri, 13 May 2005 21:54:19 -0500 (CDT)

First, I want to apologize if the following inquiry is not conventional
practice on the mailing list.  Please advise me if it isn't.

Ok, onto my question:  First the platform: x86 with RedHat Enterprise 3 box
running the Linux 2.4.21 kernel with glibc 2.3.2.

I have a threaded program that aborts whenever I cancel a thread.  The 
main thread spawns the first child thread and joins it.  All threads 
except the main thread masks off all signals.

        sigfillset(&maskall);
        pthread_sigmask(SIG_SETMASK, &maskall, NULL);

The child enters a loop waiting from keyboard commands.  On command 
'start', I create a worker thread that just loops continuously.  On 
'stop', I cancel the worker thread.  Only 1 worker thread exists at any 
one time.

If I create the worker thread detached and do not call 
pthread_setcancelstate() or pthread_testcancel(), the cancellation works 
fine.  The command thread joins the worker thread and I can follow it with 
another 'start' command and the command thread starts another worker 
thread.  Ad infinitum.

However, if I call pthread_setcancelstate() and/or pthread_testcancel()
inside the worker thread's loop, when I say 'stop' and the command thread
then cancels the worker, I get a SIGABRT and my entire process (I say again,
my process) is aborted.  

Is this the way it is supposed to work?  Doesn't seem reasonable to me.
Basically, I want to protect a critical piece of code inside the worker's
loop, defer all cancellation till after the critical section, and have the
cancellation proceed normally with the command thread joining the worker.  

Can someone advise?

Ken




reply via email to

[Prev in Thread] Current Thread [Next in Thread]