Bugzilla will be upgraded to version 5.0 on December 2, 2018. The outage period for the upgrade will start at 0:00 UTC and have a duration of 12 hours
Bug 82027 - Cannot create and delete threads indefinitely
Cannot create and delete threads indefinitely
Product: Red Hat Linux
Classification: Retired
Component: glibc (Show other bugs)
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2003-01-16 10:02 EST by Jacques ANTHOINE
Modified: 2016-11-24 10:05 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-01-20 13:00:09 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Jacques ANTHOINE 2003-01-16 10:02:20 EST
Description of problem:
An main thread creates several threads and then delete them with pthread_cancel
() function.
After many tries, the pthread_create() function fails with EAGAIN errno.

The created threads are waiting on inputs from a device and cannot test the 
annulation point.

It seems to me the the max number of threads (1024) is reached.
In the linux documentation, I read the pthread_cancel() force the cancelled 
thread to call the pthread_exit() function. 

It seems to me the thread number is not decremented on a pthread_cancel() 
and/or pthread_exit().

Version-Release number of selected component (if applicable):
RedHat 7.2 , kernel 2.4

How reproducible:


Steps to Reproduce:
1. Test the following program :

	#include <pthread.h>
	#include <stdio.h>
	#include <stdlib.h>
	#include <stdio.h>
	#include <string.h>
	#include <unistd.h>

	#define NB_THREADS	10

	void * fn_thread (void * numero);

	static int compteur = 0;

int main (void)

	pthread_t thread [NB_THREADS];
	int       i;
	int       ret;

	while (1)
		compteur ++;
		for (i = 0; i < NB_THREADS; i ++)
			if ((ret = pthread_create (& thread [i], 
                                    (void *) i)) != 0) 
				perror("Error in pthread_create ");
				printf ("%s", strerror (ret));
				exit (1);
		printf("Create %d threads \n",compteur*NB_THREADS);

		for (i = 0; i < NB_THREADS; i ++)
			pthread_cancel (thread [i]);

	return (0);

void * fn_thread (void * num)
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);

	while (1) {

2. Build the executable code with the Makefile :


CFLAGS = -Wall -pedantic -g -D_REENTRANT -lpthread

EXECUTABLES=	exemple_create


clean : 
	@rm -f core *.o *.out
	@rm -f ${EXECUTABLES}

3. Run the program and get the following trace

[root@quickthemis 34]# ./exemple_create
Create 10 threads
Create 20 threads
Create 30 threads
Create 40 threads
Create 50 threads
Create 60 threads
Create 70 threads
Create 80 threads
Create 90 threads
Create 100 threads
Create 110 threads
Create 120 threads
Create 130 threads
Create 140 threads
Create 150 threads
Create 160 threads
Create 170 threads
Create 180 threads
Create 190 threads
Create 200 threads
Create 210 threads
Create 220 threads
Create 230 threads
Create 240 threads
Create 250 threads
Error in pthread_create : Interrupted system call
Actual results:

The threads are deleted by the pthread_cancel . Then threads creation failed on 
EAGAIN errno after 25 loops.

Expected results:

This program must run without limits

Additional info:
Comment 1 Jakub Jelinek 2003-01-20 13:00:09 EST
Well, by default threads are created in PTHREAD_CREATE_JOINABLE detachstate,
which means unless you pthread_join on them, their resources aren't freed.
See man pthread_attr_setdetachstate(3), pthread_detach(3), pthread_join(3).
Comment 2 Jacques ANTHOINE 2003-01-21 03:55:12 EST
Thanks a lot for your help.

Now, all is OK.

Best regards,

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