Sunday, 25 August 2013

What is the meaning of \"reclaimation of storage\" with respect to threads\' pthread_join() & pthread_detach()?

What is the meaning of \"reclaimation of storage\" with respect to threads\' pthread_join() & pthread_detach()? References I wrote a simple thread program: #include #include #include #include #define THREADS 5 void* HelloWorld(void *t) { printf(\"Thread ID #%lu: (%lu) Hello World !!\\n\", pthread_self(), (unsigned long)t); return NULL; } int main() { pthread_t thread[THREADS]; uint32_t i; int err; for(i = 0; i < THREADS; ++i) { err = pthread_create(&thread[i], NULL, &HelloWorld, (void*)(unsigned long long)i); if(err != 0) { printf(\"Error %d: Thread %d Creation Unsuccessful !!\\n\", err, i); } printf(\"Thread %lu in main()\\n\", pthread_self()); } /* for(i = 0; i < THREADS; ++i) { pthread_join(thread[i], NULL); // Error checking implemented } */ return 0; } But on using valgrind as: valgrind --tool=memcheck --leak-check=full --show-reachable=yes ./hello It shows same output for memory usage/leaks whether pthread_join() is used or not used in the program. Please explain this behaviour as I read here that: The pthread_join() or pthread_detach() function should eventually be called for every thread that is created with the detachstate attribute set to PTHREAD_CREATE_JOINABLE so that storage associated with the thread may be reclaimed. How the storage is reclaimed if I do not call pthread_join()

No comments:

Post a Comment