Conditional variables Flashcards
Give the definition:
No 2 threads access a critical section at the same time & run at the same time. Enabled by locks.
Mutual exclusion
Give the definition:
A thread that wishes to check whether a condition is true before execution uses this. It ensures that a thread runs after the one before it completes.
Conditional variable & semaphores
What sort of primitives are conditional variables?
Synchronization primitives
Why are conditional variables used with mutex?
To prevent race conditions
Which function of a conditional variable is this?
Puts itself on the waiting queue
wait(cv …)
Which function of a conditional variable is this?
Sends signal to CV when it’s done
signal(cv …)
Which function of a conditional variable is this?
Wakes up all waiting threads
broadcast()
Which function of a conditional variable is this?
Wakes up one waiting thread
cond_signal()
Which function of a conditional variable is this?
Wakes up all waiting threads
cond_broadcast()
What four things are a program with a conditional variable missing if the following problem can arise?
Parent can continue to sleep itself forever
A lock
State variable
Mutex
Re-check of CV
What problem is this a description of?
A buffer has a bounded size meaning that when the buffer is full, producers must wait, and when the buffer is empty, consumers must wait.
Producer/consumer problem or bounded-buffer problem
What issue will the p/c (producer/consumer) problem still have if only locks are implemented?
Continue looping
To ensure that producer wait on empty and consumer waits on fill, how many conditional variables are needed to solve the p/c problem?
2 CVs - distinguishes to types of threads
Give the definition:
An object with an integer value that we can manipulate with two routines
Semaphore
What function of a semaphore is this?
Decrements the value of the semaphore integer by one, then waits if the integer is negative
sem_wait() (in POSIX standard)
What function of a semaphore is this?
Increments the value of the semaphore integer by one, if there are 1/more threads waiting, wakes one
sem_post() (in POSIX standard)
What sort of semaphores are locks?
Binary semaphores