How to initialise a binary semaphore in C?

If you want a strictly binary semaphore on Linux, I suggest building one out of mutexes and condition variables.

If you want a strictly binary semaphore on Linux, I suggest building one out of mutexes and condition variables. Struct binary_semaphore { pthread_mutex_t mutex; pthread_cond_t cvar; int v; }; void mysem_post(struct binary_semaphore *p) { pthread_mutex_lock(&p->mutex); if (p->v == 1) /* error */ p->v += 1; pthread_cond_signal(&p->cvar); pthread_mutex_unlock(&p->mutex); } void mysem_wait(struct binar_semaphore *p) { pthread_mutex_lock(&p->mutex); while (!p->v) pthread_cond_wait(&p->cvar, &p->mutex); p->v -= 1; pthread_mutex_unlock(&p->mutex); }.

Great thanks! I had ended up doing pretty much that. – austinmarton Sep 20 at 0:56.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send