Bug 120125 - pthread_setcancelstate() can't disable pthread_cancel()
pthread_setcancelstate() can't disable pthread_cancel()
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc (Show other bugs)
3.0
i686 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2004-04-06 04:52 EDT by Shao Hui
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version: glibc-2.3.2-95.20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2004-04-07 23:11:47 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Shao Hui 2004-04-06 04:52:58 EDT
Description of problem:
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL) behave very strange.
it can't disable pthread_cancel(). see the code below.

Version-Release number of selected component (if applicable):
glibc-2.3.2-95.3
kernel-2.4.21-9.0.1.EL

How reproducible:
#include <stdio.h>
#include <pthread.h>

pthread_t t1;
pthread_t t2;

void *thread1(void *arg)
{
	printf("thread1: started\n");
	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
	printf("thread1: disable cancel\n");
	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
	sleep(3);
	printf("thread1: here we go\n");
	printf("thread1: enable cancel\n");
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
	printf("thread1: test cancel\n");
	pthread_testcancel();
	printf("thread1: return\n");
}

void *thread2(void *arg)
{
	printf("thread2: started\n\n");
	sleep(1);
	printf("thread2: cancel thread1\n");
	pthread_cancel(t1);
	printf("thread2: thread canceled\n");
	printf("thread2: return\n");
}

main(int argc, char **argv)
{
	pthread_create(&t1, NULL, thread1, NULL);
	pthread_create(&t2, NULL, thread2, NULL);
	pthread_join(t2, NULL);
	printf("thread2: exited\n\n");
	pthread_join(t1, NULL);
	printf("thread1: exited\n");
}

gcc -o test test.c -lpthread
./test
thread1: started
thread1: disable cancel
thread2: started

thread2: cancel thread1
thread2: thread canceled
thread2: return
thread2: exited

thread1: here we go
thread1: exited

export LD_ASSUME_KERNEL=2.4.1
./test
thread1: started
thread1: disable cancel
thread2: started

thread2: cancel thread1
thread2: thread canceled
thread2: return
thread2: exited

thread1: here we go
thread1: enable cancel
thread1: test cancel
thread1: exited

after thread1 print "here we go", thread1 exited. Is there a cancel
testing
exactly after printf()? but the cancelstate should be disabled. when I
export
LD_ASSUME_KERNEL=2.4.1, the result looks good. is it a bug of NPTL? or
just a
feature?

Steps to Reproduce:
1.
2.
3.
  
Actual results:


Expected results:


Additional info:
Comment 1 Jakub Jelinek 2004-04-07 07:21:44 EDT
Works for me with current RHEL3 U2 glibc
(ftp://people.redhat.com/jakub/glibc/2.3.2-95.20/)
as well as FC2t2 glibc.
There have been several fixes related to PTHREAD_CANCEL_DISABLE in
glibc after RHEL3 has been released.
Comment 2 Shao Hui 2004-04-07 23:11:47 EDT
yes, glibc-2.3.2-95.20 works for me, thanks a lot :)

Note You need to log in before you can comment on or make changes to this bug.