1 /* Copyright (C) 2003, 2004 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
30 static pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
31 static pthread_mutex_t mut
= PTHREAD_MUTEX_INITIALIZER
;
32 static pthread_barrier_t bN1
;
33 static pthread_barrier_t b2
;
39 if (pthread_mutex_lock (&mut
) != 0)
41 puts ("child: 1st mutex_lock failed");
45 int e
= pthread_barrier_wait (&b2
);
46 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
48 puts ("child: 1st barrier_wait failed");
52 if (pthread_cond_wait (&cond
, &mut
) != 0)
54 puts ("child: cond_wait failed");
58 if (pthread_mutex_unlock (&mut
) != 0)
60 puts ("child: mutex_unlock failed");
64 e
= pthread_barrier_wait (&bN1
);
65 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
67 puts ("child: 2nd barrier_wait failed");
78 if (pthread_barrier_init (&bN1
, NULL
, N
+ 1) != 0)
80 puts ("barrier_init failed");
84 if (pthread_barrier_init (&b2
, NULL
, 2) != 0)
86 puts ("barrier_init failed");
92 if (pthread_attr_init (&at
) != 0)
94 puts ("attr_init failed");
98 if (pthread_attr_setstacksize (&at
, 1 * 1024 * 1024) != 0)
100 puts ("attr_setstacksize failed");
105 for (r
= 0; r
< ROUNDS
; ++r
)
107 printf ("round %d\n", r
+ 1);
111 for (i
= 0; i
< N
; ++i
)
113 if (pthread_create (&th
[i
], &at
, tf
, NULL
) != 0)
115 puts ("create failed");
119 int e
= pthread_barrier_wait (&b2
);
120 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
122 puts ("parent: 1st barrier_wait failed");
127 if (pthread_mutex_lock (&mut
) != 0)
129 puts ("parent: mutex_lock failed");
132 if (pthread_mutex_unlock (&mut
) != 0)
134 puts ("parent: mutex_unlock failed");
138 /* N single signal calls. Without locking. This tests that no
140 for (i
= 0; i
< N
; ++i
)
141 if (pthread_cond_signal (&cond
) != 0)
143 puts ("cond_signal failed");
147 int e
= pthread_barrier_wait (&bN1
);
148 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
150 puts ("parent: 2nd barrier_wait failed");
154 for (i
= 0; i
< N
; ++i
)
155 if (pthread_join (th
[i
], NULL
) != 0)
157 puts ("join failed");
162 if (pthread_attr_destroy (&at
) != 0)
164 puts ("attr_destroy failed");
172 #define TEST_FUNCTION do_test ()
173 #include "../test-skeleton.c"