#include #include #include /* for exit() */ #include /* for sem_xxxx() */ sem_t semp; int val; static void *wait_fun(void *arg) { while(1) { sem_wait(&semp); sem_getvalue(&semp, &val); fprintf(stderr, "thread==> count : %d \n", val); } } int main(void) { pthread_t pthread_tid = 0; sem_post(&semp); sem_post(&semp); sem_getvalue(&semp, &val); fprintf(stderr, "main==> count : %d \n", val); #if 0 sem_post(&semp); sem_post(&semp); sem_post(&semp); #endif if (pthread_create(&pthread_tid, NULL, wait_fun, NULL) != 0 ) { printf("failed : wait_fun create \n"); exit(EXIT_FAILURE); } pthread_join(pthread_tid, NULL); exit(EXIT_SUCCESS); }