Reputation: 707
I have a few quick questions. If I create a new child thread in C, after the thread has finished its processing and it terminates, do:
Guess I posted too fast. Found the answer to the second question (for future ref): http://www.ibm.com/developerworks/linux/library/l-memory-leaks/index.html?ca=drs-
Also I would like to mention that the OS is POSIX compliant.
Thanks, Neco
Upvotes: 2
Views: 189
Reputation: 57774
Resources like memory, file handles, mutexs, etc. are not released when a thread exits. However, all process related resources are released when a process exits which includes all those types of objects.
Upvotes: 0
Reputation: 22261
As you already found out, the answer to your first question is "no". That goes for objects allocated on the heap too.
There is no parent&child relationship between threads in a process, so "parent thread" is meaningless. But, yes, threads can return a value when they exit. The prototype for a thread's toplevel function is:
void *function(void *);
Observe that the return type is void *
. Threads can return a pointer (to anything you like). This return value will be retrieved by any other thread that waits for the returning thread to complete using pthread_join()
.
Upvotes: 4