1 /*
2 * Copyright (c) 2002, Intel Corporation. All rights reserved.
3 * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 * Test that pthread_detach()
9 *
10 * Upon failure, it shall return an error number:
11 * -[EINVAL] The implemenation has detected that the value specified by
12 * 'thread' does not refer to a joinable thread.
13 * -[ESRCH] No thread could be found corresponding to that thread
14
15 * It shall not return an error code of [EINTR]
16 *
17 * STEPS:
18 * 1. Create a thread.
19 * 2.Wait 'till the thread exits.
20 * 3.Try and detach this thread.
21 * 4.Check the return value and make sure it is ESRCH
22 *
23 */
24
25 #include <pthread.h>
26 #include <stdio.h>
27 #include <errno.h>
28 #include <unistd.h>
29 #include "posixtest.h"
30
31 /* Thread function */
a_thread_func()32 void *a_thread_func()
33 {
34 pthread_exit(0);
35 return NULL;
36 }
37
38
main()39 int main()
40 {
41 pthread_t new_th;
42 int ret;
43
44 /* Create the thread */
45 if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0)
46 {
47 perror("Error creating thread\n");
48 return PTS_UNRESOLVED;
49 }
50
51 /* Wait 'till the thread returns.
52 * The thread could have ended by the time we try to join, so
53 * don't worry about it, just so long as other errors don't
54 * occur. The point is to make sure the thread has ended execution. */
55 if(pthread_join(new_th, NULL) == EDEADLK)
56 {
57 perror("Error joining thread\n");
58 return PTS_UNRESOLVED;
59 }
60
61 /* Detach the non-existant thread. */
62 ret=pthread_detach(new_th);
63
64 /* Check return value of pthread_detach() */
65 if(ret != ESRCH)
66 {
67 printf("Test FAILED: Incorrect return code: %d instead of ESRCH\n", ret);
68 return PTS_FAIL;
69
70 }
71
72 printf("Test PASSED\n");
73 return PTS_PASS;
74 }
75
76
77