Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

Detached pthreads and memory leak

$
0
0
Can somebody please explain to me why this simple code leaks memory? I believe that since pthreads are created with detached state their resources should be released inmediatly after it’s termination, but it’s not the case. My environment is Qt5.2. #include <QCoreApplication> #include <windows.h>   void *threadFunc( void *arg )     {     printf("#");     pthread_exit(NULL);     }   int main()     {     pthread_t thread;     pthread_attr_t attr;       while(1)         {         printf("\nStarting threads...\n");         for(int idx=0;idx<100;idx++)             {             pthread_attr_init(&attr);             pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);             pthread_create( &thread, &attr, &threadFunc, NULL);             pthread_attr_destroy ( &attr );             }         printf("\nSleeping 10 seconds...\n");         Sleep(10000);         }     } Thanks in advance!

Viewing all articles
Browse latest Browse all 13965