-
Notifications
You must be signed in to change notification settings - Fork 49
/
11.c
72 lines (54 loc) · 1.16 KB
/
11.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
_Static_assert(__STDC_VERSION__ > 201100, "");
/**
@file
@brief C11
[C11 @ wikipedia](https://en.wikipedia.org/wiki/C11_(C_standard_revision))
[C11 gcc status](https://gcc.gnu.org/wiki/C11Status)
*/
#include <stdnoreturn.h>
#include <stdatomic.h>
#include <math.h>
#include <assert.h>
#include <stdio.h>
#if !__STDC_NO_THREADS__
#include <threads.h>
/**
https://en.cppreference.com/w/c/thread
https://www.gnu.org/software/libc/manual/html_node/ISO-C-Threads.html
*/
int run(void *arg)
{
*(int *)arg = 1;
}
int thrd_passed;
_Static_assert(thrd_success == 0, "");
void thrd_test()
{
thrd_t thread;
int res;
int passed = 0;
res = thrd_create(&thread, run, &passed);
assert(!res);
assert(res == thrd_success);
thrd_join(thread, NULL);
assert(passed);
}
#else
#pragma message "thrd_test skipped"
void thrd_test()
{
}
#endif
#define cbrt(x) _Generic((x), long double: cbrtl, \
default: cbrt, \
float: cbrtf)(x)
int main()
{
assert(__STDC_VERSION__ > 201100);
atomic_int acnt;
++acnt; // is thread safe
assert(cbrt(1.1 * 1.1 * 1.1) == 1.1);
assert(cbrt(8) == 2);
thrd_test();
return 0;
}