yggdrasil/test.c

34 lines
830 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>
#include <unistd.h>
2024-11-19 00:09:41 +02:00
#include <sys/yggdrasil.h>
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
2024-11-17 23:32:07 +02:00
2024-11-15 23:18:04 +02:00
static void *function(void *arg) {
pthread_barrier_t *barrier = (pthread_barrier_t *) arg;
printf("[child] waiting for parent\n");
pthread_barrier_wait(barrier);
printf("[child] barrier signalled!!\n");
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;
pthread_barrier_t barrier;
2024-11-14 12:20:15 +02:00
pthread_barrier_init(&barrier, NULL, 2);
printf("[main] will make the child wait on a barrier\n");
assert(pthread_create(&thread, NULL, function, (void *) &barrier) == 0);
sleep(3);
pthread_barrier_wait(&barrier);
printf("[main] barrier signalled!!\n");
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;
}