Bug 120125 - pthread_setcancelstate() can't disable pthread_cancel()
Summary: pthread_setcancelstate() can't disable pthread_cancel()
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: glibc
Version: 3.0
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2004-04-06 08:52 UTC by Shao Hui
Modified: 2007-11-30 22:07 UTC (History)
0 users

(edit)
Clone Of:
(edit)
Last Closed: 2004-04-08 03:11:47 UTC


Attachments (Terms of Use)

Description Shao Hui 2004-04-06 08:52:58 UTC
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 11:21:44 UTC
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-08 03:11:47 UTC
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.