#include <pthread.h> #include <assert.h> #include <stdio.h> _Thread_local int x = 123; static void *function(void *arg) { printf("This is thread %u\n", pthread_self()); printf("argument: %s\n", (const char *) arg); printf("[child] x = %d\n", x); x += 1; printf("[child] x = %d\n", x); return NULL; } int main(int argc, const char **argv) { pthread_t thread; printf("[main] x = %d\n", x); x = 321; printf("[main] x = %d\n", x); assert(pthread_create(&thread, NULL, function, (void *) "thread1") == 0); pthread_join(thread, NULL); return 0; }