Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming.threads > #7884
| Newsgroups | comp.programming.threads |
|---|---|
| From | Branimir Maksimovic <branimir.maksimovic@icloud.com> |
| Subject | Re: Pthread Leaks |
| References | <fd287e25-c22e-4507-b255-152904ef9ddbn@googlegroups.com> |
| Message-ID | <13QiL.6136$GWK4.1367@fx04.iad> (permalink) |
| Organization | usenet-news.net |
| Date | 2022-12-03 22:27 +0000 |
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...
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web