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
22 #include <semaphore.h>
29 static pthread_t receiver
;
31 static pthread_barrier_t b
;
38 write (STDOUT_FILENO
, "wrong signal\n", 13);
42 if (pthread_self () != receiver
)
44 write (STDOUT_FILENO
, "not the intended receiver\n", 26);
48 if (sem_post (&sem
) != 0)
50 write (STDOUT_FILENO
, "sem_post failed\n", 16);
59 int e
= pthread_barrier_wait (&b
);
60 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
62 puts ("child: barrier_wait failed");
74 sigemptyset (&sa
.sa_mask
);
76 sa
.sa_handler
= handler
;
77 if (sigaction (SIGUSR1
, &sa
, NULL
) != 0)
79 puts ("sigaction failed");
85 if (pthread_barrier_init (&b
, NULL
, N
+ 1) != 0)
87 puts ("barrier_init failed");
93 for (i
= 0; i
< N
; ++i
)
94 if (pthread_create (&th
[i
], NULL
, tf
, NULL
) != 0)
96 puts ("create failed");
100 if (sem_init (&sem
, 0, 0) != 0)
102 puts ("sem_init failed");
106 for (i
= 0; i
< N
* 10; ++i
)
108 receiver
= th
[i
% N
];
110 if (pthread_kill (receiver
, SIGUSR1
) != 0)
112 puts ("kill failed");
116 if (TEMP_FAILURE_RETRY (sem_wait (&sem
)) != 0)
118 puts ("sem_wait failed");
123 int e
= pthread_barrier_wait (&b
);
124 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
126 puts ("barrier_wait failed");
130 for (i
= 0; i
< N
; ++i
)
131 if (pthread_join (th
[i
], NULL
) != 0)
133 puts ("join failed");
141 #define TEST_FUNCTION do_test ()
142 #include "../test-skeleton.c"