Bug 82027 - Cannot create and delete threads indefinitely
Summary: Cannot create and delete threads indefinitely
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: glibc
Version: 7.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2003-01-16 15:02 UTC by Jacques ANTHOINE
Modified: 2016-11-24 15:05 UTC (History)
1 user (show)

(edit)
Clone Of:
(edit)
Last Closed: 2003-01-20 18:00:09 UTC


Attachments (Terms of Use)

Description Jacques ANTHOINE 2003-01-16 15:02:20 UTC
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:

Easy



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], 
                                    NULL, 
                                    fn_thread, 
                                    (void *) i)) != 0) 
			{
				perror("Error in pthread_create ");
				printf ("%s", strerror (ret));
				exit (1);
			}
		printf("Create %d threads \n",compteur*NB_THREADS);
		sleep(2);

		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) {
		sleep(10);
	}
}

2. Build the executable code with the Makefile :

SHELL=/bin/sh

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

EXECUTABLES=	exemple_create



all : ${EXECUTABLES}

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 18:00:09 UTC
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 08:55:12 UTC
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.