Conditional variables Flashcards

(31 cards)

1
Q

⭐️ Give the definition:
No two threads access a critical section at the same time & run at the same time. Enabled by locks.

A

Mutual exclusion

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

⭐️ What can we use to ensure mutual exclusion?

A

Locks

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

⭐️ What method ensures that two threads don’t run at the same time?

A

Locks

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

⭐️ 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.

A

Conditional variable & semaphores

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

⭐️ What sort of primitives are conditional variables?

A

Synchronization primitives

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

⭐️ What do conditional variables have a queue of?

A

Waiting threads

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

⭐️ Why are conditional variables used with mutex?

A

To prevent race conditions

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

⭐️ Which function of a conditional variable is this?
A thread puts itself on the waiting queue

A

wait(cv …)

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

⭐️ Which function of a conditional variable is this?
A thread sends signal to CV when it’s done

A

signal(cv …)

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

Which function of a conditional variable is this?
Wakes up all waiting threads

A

broadcast()

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

Which function of a conditional variable is this?
Wakes up one waiting thread

A

cond_signal()

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

Which function of a conditional variable is this?
Wakes up all waiting threads

A

cond_broadcast()

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

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

A lock
State variable
Mutex (in child)
Re-check of CV

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

⭐️ What type of problem is the bounded-buffer problem?

A

Synchronization problem

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

⭐️ A buffer has a bounded size (T/F)

A

True

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

⭐️ 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

17
Q

⭐️ What problem can both web servers & Unix pipes experience?

A

Product/consumer problem

18
Q

⭐️ 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.

A

Producer/consumer problem or bounded-buffer problem

19
Q

In the producer/consumer problem, when the buffer is full, who must wait?

20
Q

In the producer/consumer problem, when the buffer is empty, who must wait?

21
Q

Because the bounded buffer is a shared variable, there must be … both between producers, & producers and consumers

A

synchronisation

22
Q

What does producing/consuming to/from the buffer require?

23
Q

What issue will the p/c (producer/consumer) problem still have if only locks are implemented?

A

Continue looping due to deadlock

24
Q

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?

A

2 CVs - distinguishes two types of threads

25
⭐️ What 3 things must we ensure to properly use conditional variables?
1. Have a state 2. Use of mutex (ensures no race conditions) 3. Recheck of state (using while)
26
Give the definition: An object with an integer value that we can manipulate with two routines
Semaphore
27
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)
28
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)
29
What sort of semaphores are locks?
Binary semaphores
30
⭐️ A condition variable must always be used without a mutex to avoid deadlocks (T/F)
False
31
⭐️ When a thread waits on a condition variable, it releases the associated mutex while waiting (T/F)
True