| 1 | /* Copyright (C) 2003 Free Software Foundation, Inc.
|
|---|
| 2 | This file is part of the GNU C Library.
|
|---|
| 3 | Contributed by Ulrich Drepper <[email protected]>, 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 |
|
|---|
| 26 | static void *
|
|---|
| 27 | tf1 (void *arg)
|
|---|
| 28 | {
|
|---|
| 29 | pthread_join ((pthread_t) arg, NULL);
|
|---|
| 30 |
|
|---|
| 31 | puts ("1st join returned");
|
|---|
| 32 |
|
|---|
| 33 | return (void *) 1l;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 | static void *
|
|---|
| 38 | tf2 (void *arg)
|
|---|
| 39 | {
|
|---|
| 40 | pthread_join ((pthread_t) arg, NULL);
|
|---|
| 41 |
|
|---|
| 42 | puts ("2nd join returned");
|
|---|
| 43 |
|
|---|
| 44 | return (void *) 1l;
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 | static int
|
|---|
| 49 | do_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");
|
|---|
| 57 | exit (1);
|
|---|
| 58 | }
|
|---|
| 59 | if (err != EDEADLK)
|
|---|
| 60 | {
|
|---|
| 61 | printf ("1st circular join %d, not EDEADLK\n", err);
|
|---|
| 62 | exit (1);
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | if (pthread_create (&th, NULL, tf1, (void *) pthread_self ()) != 0)
|
|---|
| 66 | {
|
|---|
| 67 | puts ("1st create failed");
|
|---|
| 68 | exit (1);
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | if (pthread_cancel (th) != 0)
|
|---|
| 72 | {
|
|---|
| 73 | puts ("cannot cancel 1st thread");
|
|---|
| 74 | exit (1);
|
|---|
| 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);
|
|---|
| 82 | exit (1);
|
|---|
| 83 | }
|
|---|
| 84 | if (r != PTHREAD_CANCELED)
|
|---|
| 85 | {
|
|---|
| 86 | puts ("1st thread not canceled");
|
|---|
| 87 | exit (1);
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | err = pthread_join (pthread_self (), NULL);
|
|---|
| 91 | if (err == 0)
|
|---|
| 92 | {
|
|---|
| 93 | puts ("2nd circular join succeeded");
|
|---|
| 94 | exit (1);
|
|---|
| 95 | }
|
|---|
| 96 | if (err != EDEADLK)
|
|---|
| 97 | {
|
|---|
| 98 | printf ("2nd circular join %d, not EDEADLK\n", err);
|
|---|
| 99 | exit (1);
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | if (pthread_create (&th, NULL, tf2, (void *) pthread_self ()) != 0)
|
|---|
| 103 | {
|
|---|
| 104 | puts ("2nd create failed");
|
|---|
| 105 | exit (1);
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | if (pthread_cancel (th) != 0)
|
|---|
| 109 | {
|
|---|
| 110 | puts ("cannot cancel 2nd thread");
|
|---|
| 111 | exit (1);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | if (pthread_join (th, &r) != 0)
|
|---|
| 115 | {
|
|---|
| 116 | puts ("cannot join 2nd thread");
|
|---|
| 117 | exit (1);
|
|---|
| 118 | }
|
|---|
| 119 | if (r != PTHREAD_CANCELED)
|
|---|
| 120 | {
|
|---|
| 121 | puts ("2nd thread not canceled");
|
|---|
| 122 | exit (1);
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | err = pthread_join (pthread_self (), NULL);
|
|---|
| 126 | if (err == 0)
|
|---|
| 127 | {
|
|---|
| 128 | puts ("2nd circular join succeeded");
|
|---|
| 129 | exit (1);
|
|---|
| 130 | }
|
|---|
| 131 | if (err != EDEADLK)
|
|---|
| 132 | {
|
|---|
| 133 | printf ("2nd circular join %d, not EDEADLK\n", err);
|
|---|
| 134 | exit (1);
|
|---|
| 135 | }
|
|---|
| 136 |
|
|---|
| 137 | exit (0);
|
|---|
| 138 | }
|
|---|
|
|---|