chapter 31: semaphores Flashcards

1
Q

what are the 3 main things about a semaphore?

A

init counter variable, sem_wait() and sem_post()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what does sem_post() do?

A

increment the variable, unblock a waiting thread if there are any

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what does sem_wait() do?

A

decrement the variable and block until semaphore is free

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly