Separate memory pthread_create ()

I am developing a C application on a Linux environment. I noticed that the following code leaks tons of memory after several hundred executions:

do { pthread_t flushThread; pthread_attr_t attr; logevent_thread_t logThread = { Db , &do_curl }; if (( pthread_attr_init ( &attr ) == 0 ) && ( pthread_attr_setdetachstate ( &attr , PTHREAD_CREATE_DETACHED ) == 0 ) ) { pthread_create ( &flushThread , &attr , (void*)FlushThread , (void*)&logThread ); pthread_attr_destroy ( &attr ); } } while(1); 

When I started with the code, I used only pthread_create (), but when I noticed a leak, I started google'd and looked for StackOverflow and found the following URLs:

This is why I initialize the attributes and start the thread "disconnected". I also destroy attributes. I can not use pthread_join (), since I do not need a blocking call, I want my thread to live on its own.

Unfortunately, the leak still exists. I have no more ideas and you will get further advice!

Thanks!


@arrowdodger: calling pthread_detach () without setting any attributes also leaks. I also tried with setdetach and pthread_detach () with no success.

@drhirsch: I know this is a leak, because when it works for me for 1 day, I get a "Out of Memory" kernel panic. Additionnaly, using the top, I can see more and more memories of my process (but I understand that the best way to change this is to use valgrind).

+1
source share
1 answer

What I'm reading from your links is that you should call pthread_detach () and not create it with the DETACHED attribute.

0
source

All Articles