Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 May 2009 15:19:30 -0400
From:      Steve Polyack <korvus@comcast.net>
To:        Peter Steele <psteele@maxiscale.com>
Cc:        #freebsd-questions <freebsd-questions@freebsd.org>
Subject:   Re: pthread_detach doesn't release memory
Message-ID:  <4A1457C2.1040901@comcast.net>
In-Reply-To: <19206470.1651242845780966.JavaMail.HALO$@halo>
References:  <19206470.1651242845780966.JavaMail.HALO$@halo>

next in thread | previous in thread | raw e-mail | index | archive | help
Peter Steele wrote:
> I create a thread using something like this: 
>
> pthread_t thread; 
> pthread_create(&thread, NULL, mythread, NULL); 
> pthread_detach(thread); 
>
> I use the detach because I want to make sure the thread's resource are reclaimed when the thread completes. However, this does not seem to work. Each time I create a thread the application's memory footprint grows by 128 bytes and this memory is never released. 
>
> Am I doing this right? 
>
>   
 From man pthread_detach:

The *pthread_detach*() function indicates that system resources for the 
specified /thread/ should be reclaimed when the thread ends. If the 
thread is already ended, resources are reclaimed immediately. *This 
routine does not cause the thread to end.

*So, unless your 'mythread' routine has successfully completed, the 
associated resources will not be reclaimed.




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4A1457C2.1040901>