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. void *
  16. _thread(void *x)
  17. {
  18. return NULL;
  19. }
  20.  
  21. int
  22. main(int argc, char *argv[])
  23. {
  24. pthread_cond_t c;
  25. pthread_mutex_t m;
  26. struct timespec ts;
  27. pthread_t t;
  28.  
  29. pthread_create(&t, NULL, _thread, NULL);
  30.  
  31. pthread_mutex_init(&m, NULL);
  32. pthread_cond_init(&c, NULL);
  33.  
  34. pthread_mutex_lock(&m);
  35.  
  36. time(&ts.tv_sec);
  37. ts.tv_sec += 5;
  38. ts.tv_nsec = 0u;
  39.  
  40. printf("timedwait: %d\n", pthread_cond_timedwait(&c, &m, &ts));
  41. printf("ETIMEDOUT: (%d)\n", ETIMEDOUT);
  42. printf("unlock: %d\n", pthread_mutex_unlock(&m));
  43.  
  44. pthread_mutex_destroy(&m);
  45. pthread_cond_destroy(&c);
  46.  
  47. return EXIT_SUCCESS;
  48. }
  49.  
  50.  
Success #stdin #stdout 0s 10488KB
stdin
Standard input is empty
stdout
timedwait: 110
ETIMEDOUT: (110)
unlock: 0