chapter 31: semaphores Flashcards
1
Q
what are the 3 main things about a semaphore?
A
init counter variable, sem_wait() and sem_post()
2
Q
what does sem_post() do?
A
increment the variable, unblock a waiting thread if there are any
3
Q
what does sem_wait() do?
A
decrement the variable and block until semaphore is free
4
Q
what does the counter variable of the semaphore do?
A
when negative, it is equal to the number of waiting threads. although generally isn’t seen by the user.
5
Q
semaphore as locks (binary semaphore) and what should the initial value be?
A
sem_wait(&m)
CS
sem_post(&m)
sem_value = 1