Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Pthread Leaks

24 views
Skip to first unread message

Carole Casten

unread,
Dec 3, 2022, 1:57:27 PM12/3/22
to
Below is a program to test leaks in Pthreads. The program creates threads and joins them. The program has a pthread_create error when i=397000.

#include <stdio.h> // printf
#include <string.h> // strcpy
#include "pthread.h"

int main(int argc, char **argv)
{
pthread_attr_t sched_attr;
pthread_t thread[8];
unsigned i,j;
int err;
void* inc_thread_nr(void* arg);


pthread_attr_init(&sched_attr);
for (i = 0; i < 10000000; i++)
{
for(j=0; j<7; j++)
{
err = pthread_create(&thread[j], &sched_attr, (void*)inc_thread_nr, NULL);
if (err != 0)
{
printf("\nError in create err=%d",err);
goto finish;
}
}
for(j=0; j<7; j++)
{
err = pthread_join(thread[j],NULL);
if (err != 0)
{
printf("\nError in join err=%d",err);
goto finish;
}
}
if(i%1000==0)
printf("\ri=%d",i);
}
finish:
exit(0);
}
void* inc_thread_nr(void* arg)
{
return(NULL);
}

Branimir Maksimovic

unread,
Dec 3, 2022, 5:27:13 PM12/3/22
to
Threads resources are freed in join, or you could create detached thread, then will
be no problems...

--

7-77-777
Evil Sinner!
with software, you repeat same experiment, expecting different results...

Carole Casten

unread,
Dec 4, 2022, 11:59:31 AM12/4/22
to
It shouldn't run out of resources if each created thread is joined.
0 new messages