1 | #include <stdio.h> |
2 | #include <pthread.h> |
3 | #include <unistd.h> |
4 | |
5 | void shared_check(); |
6 | // On some OS's (darwin) you must actually access a thread local variable |
7 | // before you can read it |
8 | int |
9 | touch_shared(); |
10 | |
11 | // Create some TLS storage within the static executable. |
12 | __thread int var_static = 44; |
13 | |
14 | void *fn_static(void *param) |
15 | { |
16 | var_static *= 2; |
17 | shared_check(); |
18 | usleep(useconds: 1); // thread breakpoint |
19 | for(;;) |
20 | usleep(useconds: 1); |
21 | } |
22 | |
23 | int main (int argc, char const *argv[]) |
24 | { |
25 | pthread_t handle; |
26 | pthread_create(newthread: &handle, NULL, start_routine: &fn_static, NULL); |
27 | touch_shared(); |
28 | for (; var_static;) |
29 | { |
30 | usleep(useconds: 1); // main breakpoint |
31 | } |
32 | |
33 | return 0; |
34 | } |
35 | |