NVIDIA Interview Question
Wouldnt the process calling pthread_join need the thread handle to identify the child to wait on?. If there are no children then on wat thread the pthread_join would be called?
thread_join is an API which causes the calling thread to wait till a particular thread be executed.
Let say we have two threads available in a process.
1- Main thread : - Generates another thread
2- Both threads are independent and start executes in parallel.
3- If let say Main thread get CPU and it doesn't execute "join" API , it might cause process to exit without waiting for the newly generated thread completes its execution.
int main()
{
create_thread(); //We have 2 threads now main thread + child thread;
main thread completes the execution;
//thread_join(); wait for child thread execution
exit(0);
}
Let me know if i am not clear enough :)
source: hxxp://sourceware.org/pthreads-win32/manual/pthread_join.html (note the hxxp instead of http)
int pthread_join(pthread_t th, void **thread_return);
Return Value
On success, the return value of th is stored in the location pointed to by thread_return, and 0 is returned. On error, a non-zero error code is returned.
Errors
ESRCH
No thread could be found corresponding to that specified by th.
since we haven't created the thread and we are asking the parent to wait for it...it will do nothing imo...i tried it on linux
- Anonymous October 27, 2009