/*
 * Exemplo 1: FUTEX_WAKE. Thread 0 acorda thread 1.
 */
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <pthread.h>
#include "myfutex.h"

int futex_addr = 0;

void* f_thread1(void *v) {
  futex_addr = 0;
  futex_wait(&futex_addr, 0);
  printf("Thread 0.\n");
  return NULL;
}

void* f_thread0(void *v) {
  sleep(5);
  futex_wake(&futex_addr, 1);  
  printf("Thread 1.\n");
  return NULL;
}

int main() {
  pthread_t thr0, thr1; 

  pthread_create(&thr1, NULL, f_thread1, NULL);
  pthread_create(&thr0, NULL, f_thread0, NULL);
  
  pthread_exit(0);
}