Chapter 7: Synchronization Examples (1) Flashcards

(38 cards)

1
Q

What are the two ‘Classic Problems of Synchronization’ mentioned in the source material?

A

The Bounded-Buffer Problem and the Dining-Philosophers Problem.

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

What is the primary use for classic synchronization problems like the Bounded-Buffer and Dining-Philosophers problems?

A

They are used for testing nearly every newly proposed synchronization scheme.

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

What synchronization primitive is traditionally used to present solutions to classic synchronization problems?

A

Semaphores.

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

In the context of classic synchronization problems, what primitive could be used as an alternative to binary semaphores?

A

Mutex locks.

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

In the Bounded-Buffer problem solution, what is the initial value of the mutex semaphore?

A

The mutex semaphore is initialized to 1.

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

What is the purpose of the mutex semaphore in the Bounded-Buffer problem solution?

A

It provides mutual exclusion for access to the buffer manipulation code.

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

In the Bounded-Buffer problem, the empty semaphore is initialized to ‘n’. What does ‘n’ represent?

A

‘n’ represents the number of empty buffers (slots) available in the bounded buffer.

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

In the Bounded-Buffer problem solution, what is the initial value of the full semaphore?

A

The full semaphore is initialized to 0.

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

What does the value of the full semaphore represent in the Bounded-Buffer problem?

A

It represents the number of full buffers (slots) available in the bounded buffer.

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

In the Bounded-Buffer problem, what is the first operation the producer process performs inside its loop to add an item?

A

wait(empty).

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

Why must the producer in the Bounded-Buffer problem execute wait(empty) before adding an item to the buffer?

A

To ensure there is an empty slot available to place the new item, blocking if the buffer is full.

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

In the Bounded-Buffer problem, what is the second operation the producer process performs inside its loop?

A

wait(mutex).

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

After gaining access to the buffer, what is the first operation the producer process performs to release resources?

A

signal(mutex).

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

What is the final operation the producer process performs in its loop after adding an item to the buffer?

A

signal(full).

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

Why does the producer in the Bounded-Buffer problem execute signal(full) after adding an item?

A

To increment the count of full slots, potentially waking up a waiting consumer.

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

In the Bounded-Buffer problem, what is the first operation the consumer process performs inside its loop to remove an item?

17
Q

Why must the consumer in the Bounded-Buffer problem execute wait(full) before removing an item?

A

To ensure there is a full slot available to consume from, blocking if the buffer is empty.

18
Q

In the Bounded-Buffer problem, what is the second operation the consumer process performs inside its loop?

19
Q

After removing an item from the buffer, what is the first operation the consumer process performs to release resources?

A

signal(mutex).

20
Q

What is the final operation the consumer process performs in its loop after removing an item from the buffer?

A

signal(empty).

21
Q

Why does the consumer in the Bounded-Buffer problem execute signal(empty) after removing an item?

A

To increment the count of empty slots, potentially waking up a waiting producer.

22
Q

Describe the symmetry between the producer and consumer in the Bounded-Buffer problem.

A

One can view the producer as producing full buffers for the consumer, or the consumer as producing empty buffers for the producer.

23
Q

Describe the physical setup of the Dining-Philosophers problem.

A

Five philosophers share a circular table with five chairs, a central bowl of rice, and five single chopsticks.

24
Q

In the Dining-Philosophers problem, what must a philosopher acquire to be able to eat?

A

The philosopher must acquire the two chopsticks that are closest to them (left and right).

25
How many chopsticks can a philosopher in the Dining-Philosophers problem pick up at one time?
A philosopher can pick up only one chopstick at a time.
26
What does a philosopher do after they are finished eating in the Dining-Philosophers problem?
The philosopher puts down both chopsticks and starts thinking again.
27
In the simple semaphore solution to the Dining-Philosophers problem, what does each semaphore in the `chopstick[5]` array represent?
Each semaphore represents a single chopstick on the table.
28
What is the initial value for all semaphores in the `chopstick[5]` array in the Dining-Philosophers solution?
All elements of the `chopstick` array are initialized to 1.
29
In the semaphore solution for the Dining-Philosophers problem, which operation is used to grab a chopstick?
The `wait()` operation is executed on the semaphore representing that chopstick.
30
In the semaphore solution for the Dining-Philosophers problem, which operation is used to release a chopstick?
The `signal()` operation is executed on the semaphore representing that chopstick.
31
In the code for philosopher `i`, what does the operation `wait(chopstick[i])` attempt to do?
It attempts to acquire the philosopher's left chopstick.
32
In the code for philosopher `i`, what does the operation `wait(chopstick[(i+1) % 5])` attempt to do?
It attempts to acquire the philosopher's right chopstick.
33
What is the main reason that the simple semaphore-based solution to the Dining-Philosophers problem must be rejected?
It must be rejected because it could create a deadlock.
34
Describe the specific scenario that leads to deadlock in the simple Dining-Philosophers solution.
Deadlock occurs if all five philosophers become hungry simultaneously and each grabs their left chopstick.
35
When the deadlock scenario occurs in the Dining-Philosophers problem, what will the value of all elements in the `chopstick` semaphore array be?
All the elements of `chopstick` will be equal to 0.
36
One remedy to the Dining-Philosophers deadlock is to limit the number of philosophers at the table. What is the maximum number allowed?
Allow at most four philosophers to be sitting simultaneously at the table.
37
A remedy for the Dining-Philosophers problem is to allow a philosopher to pick up chopsticks only if both are available. How must this be implemented?
The philosopher must pick them up in a critical section.
38
What is the 'asymmetric solution' to the Dining-Philosophers deadlock problem?
An odd-numbered philosopher picks up the left chopstick first, while an even-numbered philosopher picks up the right chopstick first.