Conditional variables Flashcards
(31 cards)
⭐️ Give the definition:
No two threads access a critical section at the same time & run at the same time. Enabled by locks.
Mutual exclusion
⭐️ What can we use to ensure mutual exclusion?
Locks
⭐️ What method ensures that two threads don’t run at the same time?
Locks
⭐️ Give the definition:
A thread 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
⭐️ What do conditional variables have a queue of?
Waiting threads
⭐️ Why are conditional variables used with mutex?
To prevent race conditions
⭐️ Which function of a conditional variable is this?
A thread puts itself on the waiting queue
wait(cv …)
⭐️ Which function of a conditional variable is this?
A thread 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 (in child)
Re-check of CV
⭐️ What type of problem is the bounded-buffer problem?
Synchronization problem
⭐️ A buffer has a bounded size (T/F)
True
⭐️ What example of the product/consumer problem is this?
1. Producer puts requests in a queue
2. Consumers picks requests form the queue to process
Web servers
⭐️ What problem can both web servers & Unix pipes experience?
Product/consumer problem
⭐️ 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
In the producer/consumer problem, when the buffer is full, who must wait?
Producers
In the producer/consumer problem, when the buffer is empty, who must wait?
Consumer
Because the bounded buffer is a shared variable, there must be … both between producers, & producers and consumers
synchronisation
What does producing/consuming to/from the buffer require?
Locking
What issue will the p/c (producer/consumer) problem still have if only locks are implemented?
Continue looping due to deadlock
To ensure that a producer waits on empty and consumer waits on fill, how many conditional variables are needed to solve the p/c problem?
2 CVs - distinguishes two types of threads