Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming.threads > #7883 > unrolled thread

Pthread Leaks

Started byCarole Casten <carole.casten@gmail.com>
First post2022-12-03 10:57 -0800
Last post2022-12-04 08:59 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.programming.threads


Contents

  Pthread Leaks Carole Casten <carole.casten@gmail.com> - 2022-12-03 10:57 -0800
    Re: Pthread Leaks Branimir Maksimovic <branimir.maksimovic@icloud.com> - 2022-12-03 22:27 +0000
      Re: Pthread Leaks Carole Casten <carole.casten@gmail.com> - 2022-12-04 08:59 -0800

#7883 — Pthread Leaks

FromCarole Casten <carole.casten@gmail.com>
Date2022-12-03 10:57 -0800
SubjectPthread Leaks
Message-ID<fd287e25-c22e-4507-b255-152904ef9ddbn@googlegroups.com>
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);
}

[toc] | [next] | [standalone]


#7884

FromBranimir Maksimovic <branimir.maksimovic@icloud.com>
Date2022-12-03 22:27 +0000
Message-ID<13QiL.6136$GWK4.1367@fx04.iad>
In reply to#7883
On 2022-12-03, Carole Casten <carole.casten@gmail.com> wrote:
> 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);
> }
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...

[toc] | [prev] | [next] | [standalone]


#7885

FromCarole Casten <carole.casten@gmail.com>
Date2022-12-04 08:59 -0800
Message-ID<f4dcd9e1-517b-419c-bf02-a8401a6d1ba5n@googlegroups.com>
In reply to#7884
It shouldn't run out of resources if each created thread is joined.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.programming.threads


csiph-web