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