← BYTES
Unix IPC·Starter·Ref: 15.1.78

What do the POSIX functions sem_wait() and sem_post() basically do?

Have a question about this video? Mention reference 15.1.78 when you contact us.

a.sem_wait() permanently deletes a semaphore, and sem_post() creates a new one
b.sem_wait() decrements a semaphore's count, blocking if the count would go below zero; sem_post() increments the count, potentially waking a thread that was blocked in sem_wait()
c.Both functions do the exact same thing with two different names
d.sem_wait() and sem_post() are used exclusively for network socket operations, unrelated to threading
sem_wait() ('wait on', sometimes called P) is how a thread consumes one unit of whatever the semaphore represents, blocking if none are currently available; sem_post() ('signal', sometimes called V) is how a thread makes one more unit available, potentially unblocking a thread that was waiting.

Find this on YouTube & Instagram

Every BYTES video is tagged with its reference number and topic — search any of these on YouTube or Instagram to find this one:

#BYTES#BYTES15178#UnixIPC