1 /* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
27 static int do_test (void);
29 #define TEST_FUNCTION do_test ()
30 #include "../test-skeleton.c"
32 static pthread_cond_t c
= PTHREAD_COND_INITIALIZER
;
33 static pthread_mutex_t m
= PTHREAD_MUTEX_INITIALIZER
;
34 static pthread_barrier_t b
;
40 write_message ("handler called\n");
52 sigaddset (&ss
, SIGUSR1
);
53 if (pthread_sigmask (SIG_BLOCK
, &ss
, NULL
) != 0)
55 puts ("child: sigmask failed");
59 if (pthread_mutex_lock (&m
) != 0)
61 puts ("child: mutex_lock failed");
65 int e
= pthread_barrier_wait (&b
);
66 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
68 puts ("child: barrier_wait failed");
72 /* Compute timeout. */
74 (void) gettimeofday (&tv
, NULL
);
76 TIMEVAL_TO_TIMESPEC (&tv
, &ts
);
80 /* This call should never return. */
81 if (pthread_cond_timedwait (&c
, &m
, &ts
) != ETIMEDOUT
)
83 puts ("cond_timedwait didn't time out");
97 sigemptyset (&sa
.sa_mask
);
99 sa
.sa_handler
= handler
;
100 if (sigaction (SIGUSR1
, &sa
, NULL
) != 0)
102 puts ("sigaction failed");
106 if (pthread_barrier_init (&b
, NULL
, 2) != 0)
108 puts ("barrier_init failed");
112 if (pthread_create (&th
, NULL
, tf
, NULL
) != 0)
114 puts ("create failed");
118 int e
= pthread_barrier_wait (&b
);
119 if (e
!= 0 && e
!= PTHREAD_BARRIER_SERIAL_THREAD
)
121 puts ("barrier_wait failed");
125 if (pthread_mutex_lock (&m
) != 0)
127 puts ("mutex_lock failed");
131 /* Send the thread a signal which it has blocked. */
132 if (pthread_kill (th
, SIGUSR1
) != 0)
134 puts ("kill failed");
138 if (pthread_mutex_unlock (&m
) != 0)
140 puts ("mutex_unlock failed");
145 if (pthread_join (th
, &r
) != 0)
147 puts ("join failed");
152 puts ("return value wrong");