akaros/tests/futex_timeout.c
<<
>>
Prefs
   1#include <stdio.h>
   2#include <stdlib.h>
   3#include <parlib/parlib.h>
   4#include <parlib/vcore.h>
   5#include <futex.h>
   6#include <pthread.h>
   7
   8#define NUM_THREADS 10
   9pthread_t thandlers[NUM_THREADS];
  10
  11void *handler(void *arg)
  12{
  13        int id = pthread_self()->id;
  14        int var = 0;
  15        struct timespec timeout = {
  16                .tv_sec = id,
  17                .tv_nsec = 0
  18        };
  19
  20        printf("Begin thread: %d\n", id);
  21        futex(&var, FUTEX_WAIT, 0, &timeout, NULL, 0);
  22        printf("End thread: %d\n", id);
  23        return 0;
  24}
  25
  26int main(int argc, char **argv)
  27{
  28        for (int i=0; i<NUM_THREADS; i++) {
  29                pthread_create(&thandlers[i], NULL, &handler, NULL);
  30        }
  31        for (int i=0; i<NUM_THREADS; i++) {
  32                pthread_join(thandlers[i], NULL);
  33        }
  34        return 0;
  35}
  36