05-25-2009
Doubt on pthread_exit and pthread_join
Main function creates Thread0 and Thread1 by using pthread_create systemcall.
In Thread0() {
we are calling pthread_exit(0) ;
}
and in Thread1() {
status= pthread_join(tid[0],NULL);
sprintf(ebuf,"timer6: can't join with thread0, status: %d",status);
Assert(status==0,ebuf);
}
My doubt is Will pthread_join throws errors(can't join with thread0) because Thread0 terminated and again trying to join with Thread1 right??
Please let me know..
Below problem happens sometimes,but not reproducible everytime.
Failure message:
==============
timer6: can't join with thread0, status: 3
I have a doubt,that through pthread_exit(0); will Thread0 terminates?? If Thread0 terminates then why to call pthread_join function again??
Please clarify..
Am not able to get the answer..Please help me in understanding it.
Thanks in Advance,
Mansa
10 More Discussions You Might Find Interesting
1. UNIX for Dummies Questions & Answers
I would like to write my own version of pthread_join and some of the other pthread function. Does some know any pages that have som examples of doing this?? (1 Reply)
Discussion started by: bigblop
1 Replies
2. UNIX for Advanced & Expert Users
We had written an application in which we create worker thread.
So the main thread will create the worker thread. After some time
the child thread(Worker thread) will call pthread_exit().
This function was written in try{} and there occured an Exception
and is handled in catch(...)... (0 Replies)
Discussion started by: platso
0 Replies
3. Linux
Hello All,
The problem i'm experiencing is with the following code:
#include <pthread.h>
#include <stdio.h>
int main(void)
{
(void) pthread_join(155555, NULL);
printf("done");
return 0;
}
I'm getting on terminal segmentation fault .
System used:... (0 Replies)
Discussion started by: crocodil
0 Replies
4. UNIX for Advanced & Expert Users
Hi,
I would like to know if the call
of pthread_join( thread,&status) for a thread already created
in main function will free the memory allocated to thread after the pthread_join retruns or should I wait the
termination of main function?
Is there any need to cancel or exit the thread if I... (0 Replies)
Discussion started by: Behnaz
0 Replies
5. Programming
Hi...
this simple code has warning messages but it work..
void *th(void *g){
int y = 10;
pthread_exit((void*)y);
}
int main(int argn, char ** argp){
void * ret;
pthread_t thread;
pthread_create(&thread, NULL, th, NULL);
pthread_join(thread,... (10 Replies)
Discussion started by: prompt
10 Replies
6. Shell Programming and Scripting
Hi,
I have a file with multiple entries and I have calculated the percentages. Now I want to know how many of my entries are there between 1-10% 11-20% and so on..
chr1_14401_14450 0.211954217888936
chr1_14451_14500 1.90758796100042
chr1_14501_14550 4.02713013988978... (1 Reply)
Discussion started by: Diya123
1 Replies
7. Programming
Hi,
I am new to multithreaded programming. When creating a thread to run a specific function, does the function need to have a pthread_exit ?
Is pthread_exit analogous to a return in a function? (3 Replies)
Discussion started by: sanjayc
3 Replies
8. Red Hat
I need help in opening the .exe files in linux. As i have downloaded ubuntu os from trail version.
after executing the the file name in terminal it is stating that get archive files for opening the .exe files.
But i am unable to get it
please help me (2 Replies)
Discussion started by: yashwanthguru
2 Replies
9. Red Hat
How to create a file with specific size in RHEL6 (1 Reply)
Discussion started by: Sashi Kanth A
1 Replies
10. Shell Programming and Scripting
Hi experts,
In one of our code we have used some command like this.
name=${name##*/}
Can someone please let me know what exactly it does?
Thanks & Regards,
Sathya V. (1 Reply)
Discussion started by: Sathya83aa
1 Replies
LEARN ABOUT REDHAT
pthread_join
PTHREAD_JOIN(3) Library Functions Manual PTHREAD_JOIN(3)
NAME
pthread_join - wait for termination of another thread
SYNOPSIS
#include <pthread.h>
int pthread_join(pthread_t th, void **thread_return);
DESCRIPTION
pthread_join suspends the execution of the calling thread until the thread identified by th terminates, either by calling pthread_exit(3)
or by being cancelled.
If thread_return is not NULL, the return value of th is stored in the location pointed to by thread_return. The return value of th is
either the argument it gave to pthread_exit(3), or PTHREAD_CANCELED if th was cancelled.
The joined thread th must be in the joinable state: it must not have been detached using pthread_detach(3) or the PTHREAD_CREATE_DETACHED
attribute to pthread_create(3).
When a joinable thread terminates, its memory resources (thread descriptor and stack) are not deallocated until another thread performs
pthread_join on it. Therefore, pthread_join must be called once for each joinable thread created to avoid memory leaks.
At most one thread can wait for the termination of a given thread. Calling pthread_join on a thread th on which another thread is already
waiting for termination returns an error.
CANCELLATION
pthread_join is a cancellation point. If a thread is canceled while suspended in pthread_join, the thread execution resumes immediately and
the cancellation is executed without waiting for the th thread to terminate. If cancellation occurs during pthread_join, the th thread
remains not joined.
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.
EINVAL The th thread has been detached.
EINVAL Another thread is already waiting on termination of th.
EDEADLK
The th argument refers to the calling thread.
AUTHOR
Xavier Leroy <Xavier.Leroy@inria.fr>
SEE ALSO
pthread_exit(3), pthread_detach(3), pthread_create(3), pthread_attr_setdetachstate(3), pthread_cleanup_push(3), pthread_key_create(3).
LinuxThreads PTHREAD_JOIN(3)