1 #include <common.h> 2 3 int main(void)4main(void) { 5 sem_t *id; 6 u_int elapsed; 7 pid_t pid; 8 9 id = construct_shared_unnamed_sem(0); 10 11 pid = fork(); 12 switch (pid) { 13 case -1: 14 /* Error. */ 15 perror("fork"); 16 destruct_shared_unnamed_sem(id); 17 return 1; 18 case 0: 19 /* Child. */ 20 sleep(1); 21 sem_post(id); 22 exit(0); 23 } 24 25 if (testwait(id, &elapsed) < 0) { 26 destruct_shared_unnamed_sem(id); 27 return 1; 28 } 29 if (!ELAPSED(elapsed, 1000)) { 30 fprintf(stderr, "sem_wait() with delayed post took %ums " 31 "instead of 1000ms", elapsed); 32 destruct_shared_unnamed_sem(id); 33 return 1; 34 } 35 36 destruct_shared_unnamed_sem(id); 37 38 return 0; 39 } 40