[uClibc] Pthreads remain zombie even call pthread_detach and pthread_exit

Miquel Sayeras Oliveras u1016635 at correu.udg.es
Thu Dec 11 12:17:26 UTC 2003


Today I subcribe on uclibc maling list and I read the next mail posted by
Dörr, Dirk on Mon Oct 13 2003
______________________________________________________________________________________________

Hi!

I am currently working on an application that uses uclibc on a ucLinux 2.4
for a Coldfire µC.

In my application I want to dynamically create and destroy threads.

Creation works fine but a pthread_cancel shows no reaction. Then I tried
to destroy the threads by themself using pthread_exit. Now the threads
stop working but I can still see them in the process list as zombies.

So before I call Pthread_create I see on instance of my applicaton. After
pthread_create there are 3: My application, the thread_manager (result of
a clone() call in pthread.c)  and my thread. All of them have the state R
or S. After calling pthread_exit there are still 3 instances but one with
the state Z. After a while I will have an "army of undeads" but no
exorcist ;-) So I will run out of memory very soon.

Does anyone have an idee how I can release the resources still claimed by
the zombies?

Thanks

-- 
______________________________________________________________________________________________________________

This problem could be solved waiting(pthread_join) created thread to
exit(pthread_exit), but I try and child still remain zombies.

I call pthread_detach befor calling pthread_create thus I don't have to
wait childs, in any case all my threads remain zombies too.

Could anyone help me? I try my application on linux Mandrake and any
thread remains zombie.

Thanks.

_SOURCE CODE_

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

#define THREADS		1
pthread_t tid[THREADS];

void *prova(void *id)
{
	int *tid;
	tid = (int*)id;
	sleep(7);
	printf("Sortim del thread %d\n",*tid);
	pthread_exit(0);
}

int main()
{

	int contador;
	printf("******************************************************\n");
	printf("* Testing class Thread with syncronization or without*\n");
	printf("******************************************************\n");

	for(contador=0;contador<THREADS;contador++)
	{
		if(    0==pthread_create(  &(tid[contador]),NULL,(void*)&prova,(void
*)&(tid[contador])  )    )
		{

			if( 0==pthread_detach(tid[contador]) ) printf("Thread no esperat\n");
			else printf("error\n");

		}	else perror("Thread no creat");
   }
	/*
	printf("Esperem els threads\n");
   for(contador = 0; contador<THREADS;contador++)
	{
		printf("Esperem el thread %d...\n",tid[contador]);
		if(    0!=pthread_join(  tid[contador], NULL  )    )    perror("Error al
join");
	}
	printf("Esperats tots els threads\n");
*/
   while(1) sleep(2);
	return 0;
}

_______________________

Miquel Sayeras Oliveras
_______________________




More information about the uClibc mailing list