This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Plain text repost of Cancelling a PTHREAD_CANCEL_DISABLE thread


It's come to my attention my previous appends have been in HTML format.
My only excuse is that I'm in a different country than normal using a
different mailer. Apologies all.

I have a test program that creates a thread which has the attribute of
"PTHREAD_CANCEL_DISABLE". This child thread will issue a pthread_cond_wait()
for a condition to be raised (i.e. it will enqueue (&cond->__c_waiting, self)).
The main program attempts (and expects to fail) to pthread_cancel() this
thread before waking it with a pthread_cond_signal(). However, pthread_cancel()
is calling the extricate function (see below) without checking if the thread
is cancellable. The extricate function removes the entry from
&cond->__c_waiting. The pthread_cond_wait()is woken by the cancel but,
correctly, determines that the thread is not cancellable & ignores the signal.
The main routine then issues the pthread_cond_signal() but because the
queue entry has been removed by the extricate function it is effectively a
no-op. At this point the process is now dead in the water.

Should cancel.c be changed to detect that the thread is not cancellable or
should that test be performed in the extricate routine?

/* If the thread has registered an extrication interface, then
   invoke the interface. If it returns 1, then we succeeded in
   dequeuing the thread from whatever waiting object it was enqueued
   with. In that case, it is our responsibility to wake it up.
   And also to set the p_woken_by_cancel flag so the woken thread
   can tell that it was woken by cancellation. */

if (pextricate != NULL) {
  dorestart = pextricate->pu_extricate_func(pextricate->pu_object, th);
  th->p_woken_by_cancel = dorestart;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]