]> git.ipfire.org Git - thirdparty/glibc.git/blame - nptl/tst-join5.c
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / nptl / tst-join5.c
CommitLineData
a334319f 1/* Copyright (C) 2003 Free Software Foundation, Inc.
e320ef46
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
19
20#include <errno.h>
21#include <pthread.h>
22#include <stdio.h>
23#include <stdlib.h>
24
25
26static void *
27tf1 (void *arg)
28{
0ecb606c
JJ
29 pthread_join ((pthread_t) arg, NULL);
30
a334319f
UD
31 puts ("1st join returned");
32
33 return (void *) 1l;
e320ef46
UD
34}
35
36
37static void *
38tf2 (void *arg)
39{
0ecb606c 40 pthread_join ((pthread_t) arg, NULL);
e320ef46 41
a334319f
UD
42 puts ("2nd join returned");
43
44 return (void *) 1l;
e320ef46
UD
45}
46
47
48static int
49do_test (void)
50{
51 pthread_t th;
52
53 int err = pthread_join (pthread_self (), NULL);
54 if (err == 0)
55 {
56 puts ("1st circular join succeeded");
a334319f 57 exit (1);
e320ef46
UD
58 }
59 if (err != EDEADLK)
60 {
61 printf ("1st circular join %d, not EDEADLK\n", err);
a334319f 62 exit (1);
e320ef46
UD
63 }
64
65 if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
66 {
67 puts ("1st create failed");
a334319f 68 exit (1);
e320ef46
UD
69 }
70
71 if (pthread_cancel (th) != 0)
72 {
73 puts ("cannot cancel 1st thread");
a334319f 74 exit (1);
e320ef46
UD
75 }
76
77 void *r;
78 err = pthread_join (th, &r);
79 if (err != 0)
80 {
81 printf ("cannot join 1st thread: %d\n", err);
a334319f 82 exit (1);
e320ef46
UD
83 }
84 if (r != PTHREAD_CANCELED)
85 {
86 puts ("1st thread not canceled");
a334319f 87 exit (1);
e320ef46
UD
88 }
89
90 err = pthread_join (pthread_self (), NULL);
91 if (err == 0)
92 {
93 puts ("2nd circular join succeeded");
a334319f 94 exit (1);
e320ef46
UD
95 }
96 if (err != EDEADLK)
97 {
98 printf ("2nd circular join %d, not EDEADLK\n", err);
a334319f 99 exit (1);
e320ef46
UD
100 }
101
102 if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
103 {
104 puts ("2nd create failed");
a334319f 105 exit (1);
e320ef46
UD
106 }
107
108 if (pthread_cancel (th) != 0)
109 {
110 puts ("cannot cancel 2nd thread");
a334319f 111 exit (1);
0ecb606c 112 }
0ecb606c 113
e320ef46
UD
114 if (pthread_join (th, &r) != 0)
115 {
116 puts ("cannot join 2nd thread");
a334319f 117 exit (1);
e320ef46
UD
118 }
119 if (r != PTHREAD_CANCELED)
120 {
121 puts ("2nd thread not canceled");
a334319f 122 exit (1);
e320ef46
UD
123 }
124
125 err = pthread_join (pthread_self (), NULL);
126 if (err == 0)
127 {
a334319f
UD
128 puts ("2nd circular join succeeded");
129 exit (1);
e320ef46
UD
130 }
131 if (err != EDEADLK)
132 {
a334319f
UD
133 printf ("2nd circular join %d, not EDEADLK\n", err);
134 exit (1);
e320ef46
UD
135 }
136
a334319f 137 exit (0);
e320ef46
UD
138}
139
140#define TEST_FUNCTION do_test ()
141#include "../test-skeleton.c"