Conditional variables Flashcards

1
Q

Give the definition:
No 2 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

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.

A

Conditional variable & semaphores

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

Which function of a conditional variable is this?
Puts itself on the waiting queue

A

wait(cv …)

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

Which function of a conditional variable is this?
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
7
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
8
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
9
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
10
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
Re-check of CV

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

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

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

A

Continue looping

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

To ensure that producer wait on empty and consumer waits on fill, how many conditional variables are needed to solve the p/c problem?

A

2 CVs - distinguishes to types of threads

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

Give the definition:
An object with an integer value that we can manipulate with two routines

A

Semaphore

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

What function of a semaphore is this?
Decrements the value of the semaphore integer by one, then waits if the integer is negative

A

sem_wait() (in POSIX standard)

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

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

A

sem_post() (in POSIX standard)

17
Q

What sort of semaphores are locks?

A

Binary semaphores