yggdrasil/test.c

29 lines
635 B
C
Raw Normal View History

2024-11-15 23:18:04 +02:00
#include <pthread.h>
2024-11-11 23:50:38 +02:00
#include <assert.h>
#include <stdio.h>
2024-11-17 23:32:07 +02:00
_Thread_local int x = 123;
2024-11-15 23:18:04 +02:00
static void *function(void *arg) {
printf("This is thread %u\n", pthread_self());
printf("argument: %s\n", (const char *) arg);
2024-11-17 23:32:07 +02:00
printf("[child] x = %d\n", x);
x += 1;
printf("[child] x = %d\n", x);
2024-11-15 23:18:04 +02:00
return NULL;
}
2024-11-14 12:20:15 +02:00
2024-11-15 23:18:04 +02:00
int main(int argc, const char **argv) {
pthread_t thread;
printf("[main] &x = %p\n", &x);
2024-11-17 23:32:07 +02:00
printf("[main] x = %d\n", x);
x = 321;
printf("[main] x = %d\n", x);
2024-11-14 12:20:15 +02:00
2024-11-15 23:18:04 +02:00
assert(pthread_create(&thread, NULL, function, (void *) "thread1") == 0);
2024-11-14 12:20:15 +02:00
2024-11-15 23:18:04 +02:00
pthread_join(thread, NULL);
2024-11-11 15:19:36 +02:00
return 0;
}