Changes and additions migrated from cvs.devel.redhat.com:/cvs/devel/glibc to fedora...
[glibc.git] / nptl / tst-join5.c
blob589fac6b5f66087cbaf75bb43d955fff8811c189
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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.
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.
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. */
20 #include <errno.h>
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <stdlib.h>
26 static void *
27 tf1 (void *arg)
29 pthread_join ((pthread_t) arg, NULL);
31 puts ("1st join returned");
33 return (void *) 1l;
37 static void *
38 tf2 (void *arg)
40 pthread_join ((pthread_t) arg, NULL);
42 puts ("2nd join returned");
44 return (void *) 1l;
48 static int
49 do_test (void)
51 pthread_t th;
53 int err = pthread_join (pthread_self (), NULL);
54 if (err == 0)
56 puts ("1st circular join succeeded");
57 exit (1);
59 if (err != EDEADLK)
61 printf ("1st circular join %d, not EDEADLK\n", err);
62 exit (1);
65 if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
67 puts ("1st create failed");
68 exit (1);
71 if (pthread_cancel (th) != 0)
73 puts ("cannot cancel 1st thread");
74 exit (1);
77 void *r;
78 err = pthread_join (th, &r);
79 if (err != 0)
81 printf ("cannot join 1st thread: %d\n", err);
82 exit (1);
84 if (r != PTHREAD_CANCELED)
86 puts ("1st thread not canceled");
87 exit (1);
90 err = pthread_join (pthread_self (), NULL);
91 if (err == 0)
93 puts ("2nd circular join succeeded");
94 exit (1);
96 if (err != EDEADLK)
98 printf ("2nd circular join %d, not EDEADLK\n", err);
99 exit (1);
102 if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
104 puts ("2nd create failed");
105 exit (1);
108 if (pthread_cancel (th) != 0)
110 puts ("cannot cancel 2nd thread");
111 exit (1);
114 if (pthread_join (th, &r) != 0)
116 puts ("cannot join 2nd thread");
117 exit (1);
119 if (r != PTHREAD_CANCELED)
121 puts ("2nd thread not canceled");
122 exit (1);
125 err = pthread_join (pthread_self (), NULL);
126 if (err == 0)
128 puts ("2nd circular join succeeded");
129 exit (1);
131 if (err != EDEADLK)
133 printf ("2nd circular join %d, not EDEADLK\n", err);
134 exit (1);
137 exit (0);
140 #define TEST_FUNCTION do_test ()
141 #include "../test-skeleton.c"