1 /* Test that pthread_mutex_timedlock properly times out.
2 Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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, see
17 <http://www.gnu.org/licenses/>. */
25 pthread_mutex_t mutex
;
30 struct timespec abstime
;
31 clock_gettime (CLOCK_REALTIME
, &abstime
);
33 int ret
= pthread_mutex_timedlock (&mutex
, &abstime
);
36 puts ("mutex_timedlock didn't fail");
41 printf ("mutex_timedlock failed: %s\n", strerror (ret
));
52 pthread_mutexattr_t ma
;
54 if (pthread_mutexattr_init (&ma
) != 0)
56 puts ("mutexattr_init failed");
59 if (pthread_mutexattr_setrobust_np (&ma
, PTHREAD_MUTEX_ROBUST_NP
) != 0)
61 puts ("mutexattr_setrobust failed");
64 if (pthread_mutex_init (&mutex
, &ma
))
66 puts ("mutex_init failed");
70 if (pthread_mutexattr_destroy (&ma
))
72 puts ("mutexattr_destroy failed");
76 if (pthread_mutex_lock (&mutex
))
78 puts ("mutex_lock failed");
82 if (pthread_create (&pt
, NULL
, thr
, NULL
))
84 puts ("pthread_create failed");
88 if (pthread_join (pt
, NULL
))
90 puts ("pthread_join failed");
94 if (pthread_mutex_unlock (&mutex
))
96 puts ("mutex_unlock failed");
100 if (pthread_mutex_destroy (&mutex
))
102 puts ("mutex_destroy failed");
109 #define TEST_FUNCTION do_test ()
110 #include "../test-skeleton.c"