1 /* $NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $ */
4 * Copyright (c) 2008 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __COPYRIGHT("@(#) Copyright (c) 2008\
31 The NetBSD Foundation, inc. All rights reserved.");
32 __RCSID("$NetBSD: t_mutex.c,v 1.15 2017/01/16 16:23:41 christos Exp $");
34 #include <sys/time.h> /* For timespecadd */
35 #include <inttypes.h> /* For UINT16_MAX */
45 #include <sys/sched.h>
46 #include <sys/param.h>
52 static pthread_mutex_t mutex;
53 static pthread_mutex_t static_mutex = PTHREAD_MUTEX_INITIALIZER;
57 /* This code is used for verifying non-timed specific code */
58 static struct timespec ts_lengthy = {
62 /* This code is used for verifying timed-only specific code */
63 static struct timespec ts_shortlived = {
69 mutex_lock(pthread_mutex_t *m, const struct timespec *ts)
71 struct timespec ts_wait;
72 ATF_REQUIRE(clock_gettime(CLOCK_REALTIME, &ts_wait) != -1);
73 timespecadd(&ts_wait, ts, &ts_wait);
75 return pthread_mutex_timedlock(m, &ts_wait);
78 #define mutex_lock(a, b) pthread_mutex_lock(a)
82 mutex1_threadfunc(void *arg)
86 printf("2: Second thread.\n");
89 printf("2: Locking mutex\n");
90 mutex_lock(&mutex, &ts_lengthy);
91 printf("2: Got mutex. *param = %d\n", *param);
92 ATF_REQUIRE_EQ(*param, 20);
95 pthread_mutex_unlock(&mutex);
101 ATF_TC_HEAD(mutex1, tc)
103 atf_tc_set_md_var(tc, "descr", "Checks mutexes");
105 ATF_TC_BODY(mutex1, tc)
111 printf("1: Mutex-test 1\n");
113 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
115 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
116 PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex1_threadfunc, &x));
117 printf("1: Before changing the value.\n");
120 printf("1: Before releasing the mutex.\n");
122 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
123 printf("1: After releasing the mutex.\n");
124 PTHREAD_REQUIRE(pthread_join(new, &joinval));
126 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
127 printf("1: Thread joined. X was %d. Return value (int) was %d\n",
129 ATF_REQUIRE_EQ(x, 21);
130 ATF_REQUIRE_EQ(*(int *)joinval, 21);
131 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
136 * Increment the value using a noinline function that includes a small delay
137 * to increase the window for the RMW data race.
139 __noinline static int
142 for (volatile int i = 0; i < 100; i++) {
143 /* Small delay between read+write to increase chance of race */
149 static volatile bool thread2_started = false;
153 mutex2_threadfunc(void *arg)
155 long count = *(int *)arg;
158 thread2_started = true;
160 printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
163 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
165 global_x = increment(global_x);
169 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
172 return (void *)count;
176 ATF_TC_HEAD(mutex2, tc)
178 atf_tc_set_md_var(tc, "descr", "Checks mutexes");
180 #if defined(__powerpc__)
181 atf_tc_set_md_var(tc, "timeout", "40");
185 ATF_TC_BODY(mutex2, tc)
194 printf("1: Mutex-test 2\n");
197 #if defined(__powerpc__)
198 atf_tc_expect_timeout("PR port-powerpc/44387");
202 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
206 num_increments = count = count2 = 1000;
207 if (getenv("NUM_ITERATIONS") != NULL) {
208 num_increments = count = count2 =
209 MIN(INT_MAX, strtoul(getenv("NUM_ITERATIONS"), NULL, 10));
211 printf("Will use %d iterations\n", num_increments);
213 count = count2 = 10000000;
216 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
218 thread2_started = false;
220 PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex2_threadfunc, &count2));
222 printf("1: Thread %p\n", pthread_self());
224 while (!thread2_started) {
225 /* Wait for thread 2 to start to increase chance of race */
227 printf("1: Unlocking to start increment loop %p\n", pthread_self());
229 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
232 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
234 global_x = increment(global_x);
238 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
241 PTHREAD_REQUIRE(pthread_join(new, &joinval));
243 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
244 printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
245 global_x, (long)joinval);
247 ATF_REQUIRE_EQ_MSG(count, -1, "%d", count);
248 ATF_REQUIRE_EQ_MSG((long)joinval, -1, "%ld", (long)joinval);
249 ATF_REQUIRE_EQ_MSG(global_x, num_increments * 2, "%d vs %d", global_x,
252 ATF_REQUIRE_EQ(global_x, 20000000);
256 #if defined(__powerpc__)
257 /* XXX force a timeout in ppc case since an un-triggered race
258 otherwise looks like a "failure" */
259 /* We sleep for longer than the timeout to make ATF not
260 complain about unexpected success */
267 static volatile bool thread3_started = false;
271 mutex3_threadfunc(void *arg)
273 long count = *(int *)arg;
276 thread3_started = true;
278 printf("2: Second thread (%p). Count is %ld\n", pthread_self(), count);
281 PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
283 global_x = increment(global_x);
287 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
290 return (void *)count;
294 ATF_TC_HEAD(mutex3, tc)
296 atf_tc_set_md_var(tc, "descr", "Checks mutexes using a static "
299 #if defined(__powerpc__)
300 atf_tc_set_md_var(tc, "timeout", "40");
304 ATF_TC_BODY(mutex3, tc)
313 printf("1: Mutex-test 3\n");
316 #if defined(__powerpc__)
317 atf_tc_expect_timeout("PR port-powerpc/44387");
323 num_increments = count = count2 = 1000;
324 if (getenv("NUM_ITERATIONS") != NULL) {
325 num_increments = count = count2 =
326 MIN(INT_MAX, strtoul(getenv("NUM_ITERATIONS"), NULL, 10));
328 printf("Will use %d iterations\n", num_increments);
330 count = count2 = 10000000;
333 PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
334 PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex3_threadfunc, &count2));
336 printf("1: Thread %p\n", pthread_self());
338 while (!thread3_started) {
339 /* Wait for thread 3 to start to increase chance of race */
341 printf("1: Unlocking to start increment loop %p\n", pthread_self());
343 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
346 PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
348 global_x = increment(global_x);
352 PTHREAD_REQUIRE(pthread_mutex_unlock(&static_mutex));
355 PTHREAD_REQUIRE(pthread_join(new, &joinval));
357 PTHREAD_REQUIRE(mutex_lock(&static_mutex, &ts_lengthy));
358 printf("1: Thread joined. X was %d. Return value (long) was %ld\n",
359 global_x, (long)joinval);
361 ATF_REQUIRE_EQ_MSG(count, -1, "%d", count);
362 ATF_REQUIRE_EQ_MSG((long)joinval, -1, "%ld", (long)joinval);
363 ATF_REQUIRE_EQ_MSG(global_x, num_increments * 2, "%d vs %d", global_x,
366 ATF_REQUIRE_EQ(global_x, 20000000);
369 #if defined(__powerpc__)
370 /* XXX force a timeout in ppc case since an un-triggered race
371 otherwise looks like a "failure" */
372 /* We sleep for longer than the timeout to make ATF not
373 complain about unexpected success */
380 mutex4_threadfunc(void *arg)
384 printf("2: Second thread.\n");
387 printf("2: Locking mutex\n");
388 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
389 printf("2: Got mutex. *param = %d\n", *param);
392 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
398 ATF_TC_HEAD(mutex4, tc)
400 atf_tc_set_md_var(tc, "descr", "Checks mutexes");
402 ATF_TC_BODY(mutex4, tc)
406 pthread_mutexattr_t mattr;
409 printf("1: Mutex-test 4\n");
411 PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
412 PTHREAD_REQUIRE(pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE));
414 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, &mattr));
416 PTHREAD_REQUIRE(pthread_mutexattr_destroy(&mattr));
419 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
420 PTHREAD_REQUIRE(pthread_create(&new, NULL, mutex4_threadfunc, &x));
422 printf("1: Before recursively acquiring the mutex.\n");
423 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
425 printf("1: Before releasing the mutex once.\n");
427 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
428 printf("1: After releasing the mutex once.\n");
432 printf("1: Before releasing the mutex twice.\n");
434 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
435 printf("1: After releasing the mutex twice.\n");
437 PTHREAD_REQUIRE(pthread_join(new, &joinval));
439 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
440 printf("1: Thread joined. X was %d. Return value (int) was %d\n",
442 ATF_REQUIRE_EQ(x, 21);
443 ATF_REQUIRE_EQ(*(int *)joinval, 21);
444 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
448 static pthread_mutexattr_t attr5;
449 static pthread_mutex_t mutex5;
450 static int min_fifo_prio, max_fifo_prio;
453 child_func(void* arg)
457 printf("child is waiting\n");
458 res = _sched_protect(-2);
459 ATF_REQUIRE_EQ_MSG(res, -1, "sched_protect returned %d", res);
460 ATF_REQUIRE_EQ(errno, ENOENT);
461 PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy));
462 printf("child is owning resource\n");
463 res = _sched_protect(-2);
464 ATF_REQUIRE_EQ(res, max_fifo_prio);
465 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5));
466 printf("child is done\n");
472 ATF_TC_HEAD(mutex5, tc)
474 atf_tc_set_md_var(tc, "descr", "Checks mutexes for priority setting");
475 atf_tc_set_md_var(tc, "require.user", "root");
478 ATF_TC_BODY(mutex5, tc)
481 struct sched_param param;
484 min_fifo_prio = sched_get_priority_min(SCHED_FIFO);
485 max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
486 printf("min prio for FIFO = %d\n", min_fifo_prio);
487 param.sched_priority = min_fifo_prio;
489 /* = 0 OTHER, 1 FIFO, 2 RR, -1 NONE */
490 res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
491 printf("previous policy used = %d\n", res);
493 res = sched_getscheduler(getpid());
494 ATF_REQUIRE_EQ_MSG(res, SCHED_FIFO, "sched %d != FIFO %d", res,
497 PTHREAD_REQUIRE(pthread_mutexattr_init(&attr5));
498 PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&attr5,
499 PTHREAD_PRIO_PROTECT));
500 PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&attr5,
503 PTHREAD_REQUIRE(pthread_mutex_init(&mutex5, &attr5));
504 PTHREAD_REQUIRE(mutex_lock(&mutex5, &ts_lengthy));
505 printf("enter critical section for main\n");
506 PTHREAD_REQUIRE(pthread_create(&child, NULL, child_func, NULL));
507 printf("main starts to sleep\n");
509 printf("main completes\n");
510 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex5));
511 PTHREAD_REQUIRE(pthread_join(child, NULL));
514 static pthread_mutex_t mutex6;
515 static int start = 0;
516 static uintmax_t high_cnt = 0, low_cnt = 0, MAX_LOOP = 100000000;
521 struct sched_param param;
523 param.sched_priority = min_fifo_prio + 10;
524 pthread_t childid = pthread_self();
526 PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m));
527 PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m));
528 printf("high protect = %d, prio = %d\n",
529 _sched_protect(-2), param.sched_priority);
530 ATF_REQUIRE_EQ(policy, 1);
531 printf("high prio = %d\n", param.sched_priority);
534 for (int i = 0; i < 20; i++) {
535 while (high_cnt < MAX_LOOP) {
536 tmp += (123456789 % 1234) * (987654321 % 54321);
542 PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
543 if (start == 0) start = 2;
544 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
552 struct sched_param param;
554 param.sched_priority = min_fifo_prio;
555 pthread_t childid = pthread_self();
556 int res = _sched_protect(max_fifo_prio);
557 ATF_REQUIRE_EQ(res, 0);
558 PTHREAD_REQUIRE(pthread_setschedparam(childid, 1, ¶m));
559 PTHREAD_REQUIRE(pthread_getschedparam(childid, &policy, ¶m));
560 printf("low protect = %d, prio = %d\n", _sched_protect(-2),
561 param.sched_priority);
562 ATF_REQUIRE_EQ(policy, 1);
563 printf("low prio = %d\n", param.sched_priority);
566 for (int i = 0; i < 20; i++) {
567 while (low_cnt < MAX_LOOP) {
568 tmp += (123456789 % 1234) * (987654321 % 54321);
574 PTHREAD_REQUIRE(mutex_lock(&mutex6, &ts_lengthy));
577 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex6));
583 ATF_TC_HEAD(mutex6, tc)
585 atf_tc_set_md_var(tc, "descr",
586 "Checks scheduling for priority ceiling");
587 atf_tc_set_md_var(tc, "require.user", "root");
591 * 1. main thread sets itself to be a realtime task and launched two tasks,
592 * one has higher priority and the other has lower priority.
593 * 2. each child thread(low and high priority thread) sets its scheduler and
595 * 3. each child thread did several rounds of computation, after each round it
597 * 4. the child thread with low priority will call _sched_protect to increase
598 * its protect priority.
599 * 5. We verify the thread with low priority runs first.
601 * Why does it work? From the main thread, we launched the high
602 * priority thread first. This gives this thread the benefit of
603 * starting first. The low priority thread did not call _sched_protect(2).
604 * The high priority thread should finish the task first. After each
605 * round of computation, we call sleep, to put the task into the
606 * sleep queue, and wake up again after the timer expires. This
607 * gives the scheduler the chance to decide which task to run. So,
608 * the thread with real high priority will always block the thread
609 * with real low priority.
612 ATF_TC_BODY(mutex6, tc)
614 struct sched_param param;
618 min_fifo_prio = sched_get_priority_min(SCHED_FIFO);
619 max_fifo_prio = sched_get_priority_max(SCHED_FIFO);
620 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
621 printf("min_fifo_prio = %d, max_fifo_info = %d\n", min_fifo_prio,
624 param.sched_priority = min_fifo_prio;
625 res = sched_setscheduler(getpid(), SCHED_FIFO, ¶m);
626 printf("previous policy used = %d\n", res);
628 res = sched_getscheduler(getpid());
629 ATF_REQUIRE_EQ(res, 1);
630 PTHREAD_REQUIRE(pthread_create(&high, NULL, high_prio, NULL));
631 PTHREAD_REQUIRE(pthread_create(&low, NULL, low_prio, NULL));
633 PTHREAD_REQUIRE(pthread_join(low, NULL));
634 PTHREAD_REQUIRE(pthread_join(high, NULL));
636 ATF_REQUIRE_EQ(start, 1);
641 ATF_TC_HEAD(mutexattr1, tc)
643 atf_tc_set_md_var(tc, "descr", "Checks mutexattr");
646 ATF_TC_BODY(mutexattr1, tc)
648 pthread_mutexattr_t mattr;
649 int protocol, target;
651 PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
653 target = PTHREAD_PRIO_NONE;
654 PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
655 PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
656 ATF_REQUIRE_EQ(protocol, target);
659 target = PTHREAD_PRIO_INHERIT;
660 PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
661 PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
662 ATF_REQUIRE_EQ(protocol, target);
665 target = PTHREAD_PRIO_PROTECT;
666 PTHREAD_REQUIRE(pthread_mutexattr_setprotocol(&mattr, target));
667 PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr, &protocol));
668 ATF_REQUIRE_EQ(protocol, target);
672 ATF_TC_HEAD(mutexattr2, tc)
674 atf_tc_set_md_var(tc, "descr", "Checks mutexattr");
677 ATF_TC_BODY(mutexattr2, tc)
679 pthread_mutexattr_t mattr;
682 atf_tc_expect_fail("fails on i == 0 with: "
683 "pthread_mutexattr_setprioceiling(&mattr, i): Invalid argument "
687 PTHREAD_REQUIRE(pthread_mutexattr_init(&mattr));
688 int max_prio = sched_get_priority_max(SCHED_FIFO);
689 int min_prio = sched_get_priority_min(SCHED_FIFO);
690 for (int i = min_prio; i <= max_prio; i++) {
694 PTHREAD_REQUIRE(pthread_mutexattr_getprotocol(&mattr,
697 printf("priority: %d\nprotocol: %d\n", i, protocol);
698 PTHREAD_REQUIRE(pthread_mutexattr_setprioceiling(&mattr, i));
699 PTHREAD_REQUIRE(pthread_mutexattr_getprioceiling(&mattr,
701 printf("prioceiling: %d\n", prioceiling);
702 ATF_REQUIRE_EQ(i, prioceiling);
708 ATF_TC_HEAD(timedmutex1, tc)
710 atf_tc_set_md_var(tc, "descr", "Checks timeout on selflock");
713 ATF_TC_BODY(timedmutex1, tc)
716 printf("Timed mutex-test 1\n");
718 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
720 printf("Before acquiring mutex\n");
721 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
723 printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
724 PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
727 printf("Unlocking mutex\n");
728 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
732 ATF_TC_HEAD(timedmutex2, tc)
734 atf_tc_set_md_var(tc, "descr",
735 "Checks timeout on selflock with timedlock");
738 ATF_TC_BODY(timedmutex2, tc)
741 printf("Timed mutex-test 2\n");
743 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
745 printf("Before acquiring mutex with timedlock\n");
746 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
748 printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
749 PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
752 printf("Unlocking mutex\n");
753 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
757 ATF_TC_HEAD(timedmutex3, tc)
759 atf_tc_set_md_var(tc, "descr",
760 "Checks timeout on selflock in a new thread");
764 timedmtx_thrdfunc(void *arg)
766 printf("Before endeavor to reacquire timed-mutex (timeout expected)\n");
767 PTHREAD_REQUIRE_STATUS(mutex_lock(&mutex, &ts_shortlived),
773 ATF_TC_BODY(timedmutex3, tc)
777 printf("Timed mutex-test 3\n");
779 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
781 printf("Before acquiring mutex with timedlock\n");
782 PTHREAD_REQUIRE(pthread_mutex_lock(&mutex));
784 printf("Before creating new thread\n");
785 PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
787 printf("Before joining the mutex\n");
788 PTHREAD_REQUIRE(pthread_join(new, NULL));
790 printf("Unlocking mutex\n");
791 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
795 ATF_TC_HEAD(timedmutex4, tc)
797 atf_tc_set_md_var(tc, "descr",
798 "Checks timeout on selflock with timedlock in a new thread");
801 ATF_TC_BODY(timedmutex4, tc)
805 printf("Timed mutex-test 4\n");
807 PTHREAD_REQUIRE(pthread_mutex_init(&mutex, NULL));
809 printf("Before acquiring mutex with timedlock\n");
810 PTHREAD_REQUIRE(mutex_lock(&mutex, &ts_lengthy));
812 printf("Before creating new thread\n");
813 PTHREAD_REQUIRE(pthread_create(&new, NULL, timedmtx_thrdfunc, NULL));
815 printf("Before joining the mutex\n");
816 PTHREAD_REQUIRE(pthread_join(new, NULL));
818 printf("Unlocking mutex\n");
819 PTHREAD_REQUIRE(pthread_mutex_unlock(&mutex));
825 ATF_TP_ADD_TC(tp, mutex1);
826 ATF_TP_ADD_TC(tp, mutex2);
827 ATF_TP_ADD_TC(tp, mutex3);
828 ATF_TP_ADD_TC(tp, mutex4);
830 ATF_TP_ADD_TC(tp, mutex5);
831 ATF_TP_ADD_TC(tp, mutex6);
833 ATF_TP_ADD_TC(tp, mutexattr1);
834 ATF_TP_ADD_TC(tp, mutexattr2);
837 ATF_TP_ADD_TC(tp, timedmutex1);
838 ATF_TP_ADD_TC(tp, timedmutex2);
839 ATF_TP_ADD_TC(tp, timedmutex3);
840 ATF_TP_ADD_TC(tp, timedmutex4);
843 return atf_no_error();