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.
17 * Test various C11 thread-specific storage (tss(3C)) interfaces.
21 #include <sys/debug.h>
23 #define TSS_NTHREADS 128
32 ct_tss_dtor(void *arg
)
34 VERIFY3S(mtx_lock(&ct_mtx
), ==, thrd_success
);
36 VERIFY3S(mtx_unlock(&ct_mtx
), ==, thrd_success
);
42 VERIFY3P(tss_get(ct_key
), ==, NULL
);
43 VERIFY3S(tss_set(ct_key
, arg
), ==, thrd_success
);
45 VERIFY3S(mtx_lock(&ct_mtx
), ==, thrd_success
);
47 if (ct_ready
== TSS_NTHREADS
) {
48 VERIFY3S(cnd_broadcast(&ct_cnd
), ==, thrd_success
);
50 while (ct_ready
!= TSS_NTHREADS
) {
51 VERIFY3S(cnd_wait(&ct_cnd
, &ct_mtx
), ==, thrd_success
);
54 VERIFY3S(mtx_unlock(&ct_mtx
), ==, thrd_success
);
56 VERIFY3P(tss_get(ct_key
), ==, arg
);
65 thrd_t threads
[TSS_NTHREADS
];
67 VERIFY3S(tss_create(&ct_key
, ct_tss_dtor
), ==, thrd_success
);
68 VERIFY3S(mtx_init(&ct_mtx
, mtx_plain
), ==, thrd_success
);
69 VERIFY3S(cnd_init(&ct_cnd
), ==, thrd_success
);
71 for (i
= 0; i
< TSS_NTHREADS
; i
++) {
72 VERIFY3S(thrd_create(&threads
[i
], ct_tss_thr
,
73 (void *)(uintptr_t)(i
+ 100)), ==, thrd_success
);
76 for (i
= 0; i
< TSS_NTHREADS
; i
++) {
77 VERIFY3S(thrd_join(threads
[i
], NULL
), ==, thrd_success
);
80 VERIFY3S(ct_count
, ==, TSS_NTHREADS
);