5 #include <internaltypes.h>
8 # define SEM_WAIT(s) sem_wait (s)
28 if (sem_init (&s, 0, 0) != 0)
30 puts ("sem_init failed");
34 struct new_sem *is = (struct new_sem *) &s;
36 if (is->nwaiters != 0)
38 puts ("nwaiters not initialized");
42 if (pthread_create (&th, NULL, tf, &s) != 0)
44 puts ("pthread_create failed");
50 if (pthread_cancel (th) != 0)
52 puts ("pthread_cancel failed");
57 if (pthread_join (th, &r) != 0)
59 puts ("pthread_join failed");
62 if (r != PTHREAD_CANCELED && --tries > 0)
64 /* Maybe we get the scheduling right the next time. */
69 if (is->nwaiters != 0)
71 puts ("nwaiters not reset");