[444] in Pthreads mailing list archive
Re: Cleanup problems with pthreads
daemon@ATHENA.MIT.EDU (Larry V. Streepy, Jr.)
Wed Oct 2 19:53:13 1996
Date: Wed, 02 Oct 1996 17:39:25 -0600
From: "Larry V. Streepy, Jr." <streepy@healthcare.com>
To: "Marcos A. Bellezi" <bellezi@healthcare.com>
Cc: pthreads@MIT.EDU
Marcos A. Bellezi wrote:
>
> I'm developing a very thread intensive program on Linux 2.0 (pthread
> 1.60beta5) and I noted that it is very memory hungry. I checked all the code
> to find if I forgot to dealocate something but everything seens right. So,
> I wrote a small program to figure out if the problem is the pthread library.
> If you run this program (with a TOP utilitie on another window) and you go
> pressing ENTER you could note the process will increase its memory usage.
> I'm missing something or the library has problems dealocating the memory
> used by the theads ??
>
> The tiny program is:
> [program deleted]
>
> Any clues ??
Sure. Unless you make the threads run detached or perform a
pthread_join, the resources consumed by the threads are not released.
Try either of these:
void main(void)
{
pthread_t thread;
pthread_attr_t attr;
char c;
pthread_attr_init( &attr );
pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );
while(1) {
c = getchar();
if (pthread_create(&thread, &attr, dummy, (void *)0xdeadbeef))
puts("Error: creating new thread");
}
}
OR...
void main(void)
{
pthread_t thread;
char c;
while(1) {
c = getchar();
if (pthread_create(&thread, &attr, dummy, (void *)0xdeadbeef))
puts("Error: creating new thread");
pthread_join( thread );
}
}
--
Larry V. Streepy, Jr.
Chief Technical Officer, Healthcare Communications, Inc.
mailto:streepy@healthcare.com
(214) 851-7033 (Dallas Main #)
(970) 626-5028 (My office #) (970) 626-4425 (Fax)