|
Syntax #include <pthread.h> int pthread_join(pthread_t thread, void **status); Threadsafe: Yes Signal Safe: No |
The pthread_join() function waits for a thread to terminate, detaches the thread, then returns the threads exit status.
If the status parameter is NULL, the threads exit status is not returned.
The meaning of the threads exit status (value returned to the status memory location) is determined by the application except for the following conditions:
None.
If pthread_join() was not successful, the error condition returned usually indicates one of the following errors. Under some conditions, the value returned could indicate an error other than those listed here.
#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include "check.h"
int okStatus = 34;
void *threadfunc(void *parm)
{
printf("Inside secondary thread\n");
return __VOID(okStatus);
}
int main(int argc, char **argv)
{
pthread_t thread;
int rc=0;
void *status;
printf("Enter Testcase - %s\n", argv[0]);
printf("Create thread using attributes that allow join\n");
rc = pthread_create(&thread, NULL, threadfunc, NULL);
checkResults("pthread_create()\n", rc);
printf("Wait for the thread to exit\n");
rc = pthread_join(thread, &status);
checkResults("pthread_join()\n", rc);
if (__INT(status) != okStatus) {
printf("Secondary thread failed\n");
exit(1);
}
printf("Got secondary thread status as expected\n");
printf("Main completed\n");
return 0;
}
Output
Enter Testcase - QP0WTEST/TPJOIN0 Create thread using attributes that allow join Wait for the thread to exit Inside secondary thread Got secondary thread status as expected Main completed