In order to understand the "value" in
sem_init(sem_t *sem, int pshared, unsigned int value)
I think we need synchronize it with how we use the semaphore in codes:
when we want to wait for the semaphore, we call sem_wait (&mutex), and if we want to notify to make other threads' sem_wait (&mutex) run, we need call sem_post (&mutex).
But the problem is if no any other threads call sem_post (&mutex) at first(in the system initialization), what should the sem_wait (&mutex) do? It should pass or wait for other threads call sem_post (&mutex)?
The answer is in the "value" in the sem_init(). If it's zero, it means we must wait for some other threads to call sem_post() one time, then it could pass. If it's one, then the first time calling for sem_wait() will pass at once, but the second time sem_wait() will wait(if no sem_post called during them).
So the value in sem_init() means how many times we could execute sem_wait() without really waiting without any sem_post().
And we could consider the sem_wait() as:
/deadlock waiting until value is changed to bigger than 0 by another thread/
while (value<=0)
{}
value--;
And consider the sem_post() as:
value++;