-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy paththread_error.c
29 lines (27 loc) · 877 Bytes
/
thread_error.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
* thread_error.c
*
* Demonstrate detection of errors from a typical POSIX 1003.1c-1995
* function, pthread_join.
*/
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
int main (int argc, char *argv[])
{
pthread_t thread;
int status;
/*
* Attempt to join with an uninitialized thread ID. On most
* implementations, this will return an ESRCH error code. If
* the local (and uninitialized) pthread_t happens to be a valid
* thread ID, it is almost certainly that of the initial thread,
* which is running main(). In that case, your Pthreads
* implementation may either return EDEADLK (self-deadlock),
* or it may hang. If it hangs, quit and try again.
*/
status = pthread_join (thread, NULL);
if (status != 0)
fprintf (stderr, "error %d: %s\n", status, strerror (status));
return status;
}