/* cc $(pkg-config --cflags --libs glib-2.0) -o timedwait timedwait.c */

#define GLIB_DISABLE_DEPRECATION_WARNINGS

#include <stdio.h>
#include <glib.h>

int main(int argc, char **argv) {
  GMutex mutex;
  GCond cond;
  g_mutex_init(&mutex);
  g_cond_init(&cond);
  g_mutex_lock(&mutex);

  printf("waiting 1 second...\n");
  GTimeVal abs_time;
  g_get_current_time(&abs_time);
  g_time_val_add(&abs_time, G_USEC_PER_SEC);
  g_cond_timed_wait(&cond, &mutex, &abs_time);
  printf("done\n");

  g_mutex_unlock(&mutex);
  g_mutex_clear(&mutex);
  g_cond_clear(&cond);
  return 0;
}
