1 #include <common.h> 2 3 int 4 main(void) { 5 sem_t id; 6 u_int elapsed; 7 8 if (sem_init(&id, 0, 0) < 0) { 9 perror("sem_init"); 10 return 1; 11 } 12 13 /* This should fail with a timeout and leave the value at 0. */ 14 if (timedwait(&id, 2500, &elapsed, ETIMEDOUT) < 0) { 15 sem_destroy(&id); 16 return 1; 17 } 18 if (!ELAPSED(elapsed, 2500)) { 19 fprintf(stderr, "sem_timedwait() of locked sem took %ums " 20 "instead of 2500ms", elapsed); 21 sem_destroy(&id); 22 return 1; 23 } 24 if (checkvalue(&id, 0) < 0) { 25 sem_destroy(&id); 26 return 1; 27 } 28 29 if (sem_destroy(&id) < 0) { 30 perror("sem_destroy"); 31 return 1; 32 } 33 return 0; 34 } 35