NVIDIA Interview Question






Comment hidden because of low score. Click to expand.
1
of 1 vote

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 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

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?

- Anonymous January 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I guess you are right, what arguments are we giving to pthread_join if we don't have a joinable thread!

- Anonymous November 25, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

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 :)

- Shwetank Gupta October 27, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

my question is parent will keep on waiting or after some time it will exit

- Anonymous October 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hey, that's what i tried to explain in my previous mail!!!
Read it carefully.
Parent thread might exit if u don't use thread_join() [might ... becoz it depends onthread scheduler...which thread is scheduled to execute]

- Shwetank Gupta October 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@swetank but suppose parent executes thread join when will parent exit when it has not childs

- Anonymous November 01, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think deadlock...

- Jey December 29, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

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.

- Anonymous February 26, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I got a seg fault as the value of th was not initialized

- abhimanipal March 10, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It will return EINVAL (error code 22). if we pass thread_id with out creating the thread.

- ss December 13, 2012 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More