]>
git.ipfire.org Git - thirdparty/glibc.git/blob - nptl/tst-cond7.c
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@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
38 static volatile bool done
;
44 puts ("child created");
48 if (pthread_mutex_lock (&t
->lock
) != 0)
50 puts ("child: lock failed");
56 if (pthread_cond_signal (&t
->cond
) != 0)
58 puts ("child: cond_signal failed");
62 if (pthread_cond_wait (&t
->cond
, &t
->lock
) != 0)
64 puts ("child: cond_wait failed");
68 if (pthread_mutex_unlock (&t
->lock
) != 0)
70 puts ("child: unlock failed");
84 for (i
= 0; i
< N
; ++i
)
86 printf ("round %d\n", i
);
88 t
[i
] = (T
*) malloc (sizeof (T
));
91 puts ("out of memory");
95 if (pthread_mutex_init (&t
[i
]->lock
, NULL
) != 0
96 || pthread_cond_init (&t
[i
]->cond
, NULL
) != 0)
98 puts ("an _init function failed");
102 if (pthread_mutex_lock (&t
[i
]->lock
) != 0)
104 puts ("initial mutex_lock failed");
110 if (pthread_create (&t
[i
]->h
, NULL
, tf
, t
[i
]) != 0)
112 puts ("pthread_create failed");
117 if (pthread_cond_wait (&t
[i
]->cond
, &t
[i
]->lock
) != 0)
119 puts ("cond_wait failed");
124 if (pthread_cancel (t
[i
]->h
) != 0)
126 puts ("cancel failed");
130 puts ("parent: joining now");
133 if (pthread_join (t
[i
]->h
, &result
) != 0)
135 puts ("join failed");
139 if (result
!= PTHREAD_CANCELED
)
141 puts ("result != PTHREAD_CANCELED");
146 for (i
= 0; i
< N
; ++i
)
153 #define TEST_FUNCTION do_test ()
154 #include "../test-skeleton.c"