2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright 2016 Joyent, Inc.
21 #include <sys/debug.h>
23 #define CO_NTHREADS 32
25 static int co_val
= 41;
26 static mtx_t co_once_mtx
;
28 static boolean_t co_go
= B_FALSE
;
29 static once_flag co_once
= ONCE_FLAG_INIT
;
35 VERIFY3S(mtx_lock(&co_once_mtx
), ==, thrd_success
);
37 VERIFY3S(mtx_unlock(&co_once_mtx
), ==, thrd_success
);
44 VERIFY3S(mtx_lock(&co_mtx
), ==, thrd_success
);
45 while (co_go
== B_FALSE
)
46 cnd_wait(&co_cnd
, &co_mtx
);
47 VERIFY3S(mtx_unlock(&co_mtx
), ==, thrd_success
);
48 call_once(&co_once
, co_once_func
);
56 thrd_t threads
[CO_NTHREADS
];
58 VERIFY3S(mtx_init(&co_once_mtx
, mtx_plain
), ==, thrd_success
);
59 VERIFY3S(mtx_init(&co_mtx
, mtx_plain
), ==, thrd_success
);
60 VERIFY3S(cnd_init(&co_cnd
), ==, thrd_success
);
62 for (i
= 0; i
< CO_NTHREADS
; i
++) {
63 VERIFY3S(thrd_create(&threads
[i
], co_thr
, NULL
), ==,
67 VERIFY3S(mtx_lock(&co_mtx
), ==, thrd_success
);
69 VERIFY3S(mtx_unlock(&co_mtx
), ==, thrd_success
);
70 VERIFY3S(cnd_broadcast(&co_cnd
), ==, thrd_success
);
72 for (i
= 0; i
< CO_NTHREADS
; i
++) {
73 VERIFY3S(thrd_join(threads
[i
], NULL
), ==, thrd_success
);
75 VERIFY3S(co_val
, ==, 42);