1 /* Copyright (C) 2002-2023 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 pthread_mutex_t mut
;
28 static pthread_cond_t cond
= PTHREAD_COND_INITIALIZER
;
34 pthread_mutexattr_t ma
;
39 if (pthread_mutexattr_init (&ma
) != 0)
41 puts ("mutexattr_init failed");
45 if (pthread_mutexattr_settype (&ma
, PTHREAD_MUTEX_ERRORCHECK
) != 0)
47 puts ("mutexattr_settype failed");
51 if (pthread_mutex_init (&mut
, &ma
) != 0)
53 puts ("mutex_init failed");
58 if (pthread_mutex_lock (&mut
) != 0)
60 puts ("mutex_lock failed");
64 /* Waiting for the condition will fail. But we want the timeout here. */
65 if (gettimeofday (&tv
, NULL
) != 0)
67 puts ("gettimeofday failed");
71 TIMEVAL_TO_TIMESPEC (&tv
, &ts
);
72 ts
.tv_nsec
+= 500000000;
73 if (ts
.tv_nsec
>= 1000000000)
75 ts
.tv_nsec
-= 1000000000;
78 err
= pthread_cond_timedwait (&cond
, &mut
, &ts
);
81 /* This could in theory happen but here without any signal and
82 additional waiter it should not. */
83 puts ("cond_timedwait succeeded");
86 else if (err
!= ETIMEDOUT
)
88 printf ("cond_timedwait returned with %s\n", strerror (err
));
92 err
= pthread_mutex_unlock (&mut
);
95 printf ("mutex_unlock failed: %s\n", strerror (err
));
103 #define TEST_FUNCTION do_test ()
104 #include "../test-skeleton.c"