fork download
  1.  
  2. /* vim: ft=c ff=unix fenc=utf-8
  3.  * file: a.c
  4.  */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <stdint.h>
  8. #include <stdbool.h>
  9. #include <string.h>
  10. #include <unistd.h>
  11. #include <pthread.h>
  12. #include <strings.h>
  13. #include <errno.h>
  14.  
  15. int
  16. main(int argc, char *argv[])
  17. {
  18. pthread_cond_t c;
  19. pthread_mutex_t m;
  20. struct timespec ts;
  21.  
  22. pthread_mutex_init(&m, NULL);
  23. pthread_cond_init(&c, NULL);
  24.  
  25. pthread_mutex_lock(&m);
  26.  
  27. time(&ts.tv_sec);
  28. ts.tv_sec += 5;
  29. ts.tv_nsec = 0u;
  30.  
  31. printf("timedwait: %d\n", pthread_cond_timedwait(&c, &m, &ts));
  32. printf("ETIMEDOUT: (%d)\n", errno, strerror(errno), ETIMEDOUT);
  33. printf("unlock: %d\n", pthread_mutex_unlock(&m));
  34.  
  35. pthread_mutex_destroy(&m);
  36. pthread_cond_destroy(&c);
  37.  
  38. return EXIT_SUCCESS;
  39. }
  40.  
  41.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
timedwait: 110
ETIMEDOUT: (0)
unlock: 0