Bug 98094 - Bad: thread cancellation fails
Bad: thread cancellation fails
Status: CLOSED RAWHIDE
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
9
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2003-06-26 11:13 EDT by David Weber
Modified: 2016-11-24 10:18 EST (History)
1 user (show)

See Also:
Fixed In Version: 2.3.2-49
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2003-06-26 11:22:26 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description David Weber 2003-06-26 11:13:15 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2) Gecko/20021202

Description of problem:
Threads fail to cancel at sem_wait()  on rh9, glibc 2.3.2-27.9.

The symptom is that the thread fails to join after it is cancelled on a
sem_wait(). If the example program is executed from bash and is suspended (via
ctrl-Z) and resumed (via a "fg"), it cancels correctly.

Code example supplied works on rh8.0 always, and rh9 under the following
circumstances:
1) Custom built kernel (stock linux 2.4.21 from kernel.org)
2) if the following environmental variable (and value) exists 
LD_ASSUME_KERNEL=2.4.19

The code fragment was compiled as fiollows: 
   gcc -Wall -ansi-pedantic pthreads-test.c -o pthreads-test -lpthread

------------------------------------ pthreads-test.c
-------------------------------------------------
#include <semaphore.h>
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>

sem_t sem;


void *thread( void *stuff )
{
	while(1)
	{
		sem_wait(&sem);
		printf("Burp\n");
	}
}

int main(int argc, char* argv[])
{

	pthread_t t1;
	pthread_attr_t t1_attr;
	pthread_attr_init(&t1_attr);
	void *retval;
	
	pthread_attr_setdetachstate(&t1_attr, PTHREAD_CREATE_JOINABLE);

	sem_init(&sem,0,0);

	pthread_create(&t1,  &t1_attr, &thread, 0);

	/* Make sure the thread is waiting at the semaphore */
	sleep(1);
	
	sem_post(&sem);
	
	/* Must burp here and wait on the sem_wait in the thread */

	sleep(1);

	/* Thread must be at the semaphore now, so cancel it. */
	pthread_cancel(t1);
	printf("Waiting for thread to join\n");
	pthread_join(t1,&retval);

	/* If we don't get here, the thread did not cancel. Press ctrl-Z and
		type BG, and it will cancel then. Weird. */
	printf("OK. sem_wait() is a cancellation point.\n");

	return 0;

}
--------------------------------------------------------- end
---------------------------------------

Version-Release number of selected component (if applicable):
linux version 2.4.20-18.9

How reproducible:
Always

Steps to Reproduce:
1. Buiild code fragment in teh description and execute it
2. Note that it fails to report "OK. sem_wait() is a cancellation point"
3. If in bash, suspend using crtl-Z, and start using "fg". Note that it now cancells
    

Actual Results:  ./pthreads-test
Start
Burp


Expected Results:  ./pthreads-test
Burp
Waiting for thread to join
OK. sem_wait() is a cancellation point.


Additional info:

It is related to bugs 86416 and 89601. This report provides a small C program
that reproduces the problem.

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