Chapter 6: Synchronization (2) Flashcards

(116 cards)

1
Q

What issue can arise from the concurrent or parallel execution of processes that share data?

A

It can contribute to issues involving the integrity of the shared data.

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

In the bounded-buffer problem, what integer variable can be added to track the number of items in the buffer?

A

An integer variable, count, initialized to 0.

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

In the shared circular buffer implementation, what does the in pointer indicate?

A

The in pointer indicates the next free position in the buffer.

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

In the shared circular buffer implementation, what does the out pointer indicate?

A

The out pointer indicates the position of the earliest item in the buffer.

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

What condition signifies that the shared bounded buffer is empty?

A

The buffer is empty when count == 0.

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

What condition signifies that the shared bounded buffer is full?

A

The buffer is full when count == BUFFER_SIZE.

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

In the producer process code, what is the purpose of the statement while (count == BUFFER_SIZE);?

A

It forces the producer to wait, doing nothing, until there is free space in the buffer.

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

After placing a new item in the buffer, what two variables does the producer process update?

A

The producer updates the in pointer and increments the count variable.

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

In the consumer process code, what is the purpose of the statement while (count == 0);?

A

It forces the consumer to wait, doing nothing, until an item is available in the buffer.

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

After consuming an item from the buffer, what two variables does the consumer process update?

A

The consumer updates the out pointer and decrements the count variable.

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

If count is 5, and a producer executes count++ concurrently with a consumer executing count--, what are the three possible resulting values for count?

A

The value of count may be 4, 5, or 6.

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

Following the concurrent execution of count++ and count-- when count was initially 5, what is the only correct final value for count?

A

The only correct result is count == 5.

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

The high-level instruction count++ could be implemented in machine language as a sequence of what three operations?

A
  1. Load count into a register. 2. Increment the register. 3. Store the register’s value back into count.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A situation where multiple processes manipulate the same data concurrently and the outcome depends on the order of access is called a _____.

A

race condition

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

How can the race condition on the count variable be prevented?

A

By ensuring that only one process can manipulate the variable count at a time through synchronization.

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

What is the term for the segment of code in a process that accesses and updates data shared with other processes?

A

A critical section.

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

What is the key feature of a system regarding critical sections?

A

When one process is executing in its critical section, no other process is allowed to execute in its critical section.

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

What is the goal of the critical-section problem?

A

To design a protocol that processes can use to synchronize their activity and cooperatively share data.

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

What is the name of the code section where a process requests permission to enter its critical section?

A

The entry section.

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

In the general structure of a process, what section may follow the critical section?

A

The exit section.

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

What is the term for the code of a process that is not the entry, critical, or exit section?

A

The remainder section.

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

A solution to the critical-section problem must satisfy what three requirements?

A

Mutual exclusion, progress, and bounded waiting.

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

Define the ‘Mutual Exclusion’ requirement for a critical-section solution.

A

If a process is running in its critical section, then no other processes can be running in their critical sections.

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

Define the ‘Progress’ requirement for a critical-section solution.

A

If no process is in its critical section and some wish to enter, the selection of the next process cannot be postponed indefinitely.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Define the 'Bounded Waiting' requirement for a critical-section solution.
There must be a limit on the number of times other processes can enter their critical sections after a process has requested entry.
26
In a single-processor environment, what simple method could solve the critical-section problem?
Preventing interrupts from occurring while a shared variable was being modified.
27
Why is disabling interrupts not a feasible solution to the critical-section problem on multiprocessor systems?
It is time-consuming, as the message to disable interrupts must be passed to all processors.
28
Peterson's solution is a classic software-based solution to the critical-section problem for how many processes?
It is restricted to two processes.
29
Peterson's solution requires two processes to share what two data items?
An integer `turn` and a boolean array `flag[2]`.
30
In Peterson's solution, what does the variable `turn` indicate?
It indicates whose turn it is to enter its critical section.
31
In Peterson's solution, what does the `flag` array indicate?
The `flag` array indicates if a process is ready to enter its critical section.
32
In the entry section of Peterson's solution for process $P_i$, what are the first two actions taken?
First, it sets `flag[i] = true`, and then it sets `turn = j` (where j is the other process).
33
In Peterson's solution, what is the condition in the `while` loop that forces process $P_i$ to wait?
The process waits while `flag[j] && turn == j`.
34
What action does a process take in the exit section of Peterson's solution?
It sets its own flag to false (e.g., `flag[i] = false`).
35
In Peterson's solution, if both processes try to enter their critical section at the same time, what determines which one goes first?
The eventual value of the `turn` variable, determined by which process's assignment to `turn` happens last.
36
What is the primary reason Peterson's solution is not guaranteed to work on modern computer architectures?
Processors and/or compilers may reorder read and write operations that have no dependencies to improve performance.
37
For a multi-process application with shared data, what is a potential negative consequence of instruction reordering?
The reordering of instructions may lead to inconsistent or unexpected results.
38
In the example with shared variables `flag` and `x`, how could instruction reordering cause Process 1 to print 0 instead of 100?
The processor could reorder Process 2's instructions, setting `flag = true` before executing `x = 100`.
39
How can instruction reordering specifically break Peterson's solution?
If the assignments to `flag[i]` and `turn` in the entry section are reordered.
40
What is the critical consequence if instruction reordering breaks Peterson's solution?
It is possible that both processes may be active in their critical sections at the same time, violating mutual exclusion.
41
FREE CARD DIVIDER (start of 6.2)
42
Peterson's solution is not guaranteed to work with modern computer _____.
architectures
43
What can be utilized at a low level to solve the critical-section problem on modern systems?
Hardware support.
44
What are the three forms of hardware solutions mentioned for solving the critical-section problem?
Memory barriers, hardware instructions, and atomic variables.
45
One form of hardware support for synchronization involves creating _____ to ensure memory visibility between processors.
memory barriers
46
A second form of hardware support for synchronization provides special _____ that execute as a single, uninterruptible operation.
hardware instructions
47
A third form of hardware support for synchronization, _____, ensures that operations like increments and decrements are performed without interruption.
atomic variables
48
What are two ways that hardware-level synchronization solutions can be utilized?
They can be used directly as tools or as a foundation for more abstract synchronization mechanisms.
49
Why are hardware-based solutions to the critical-section problem generally inaccessible to application programmers?
Because they are complicated to use correctly.
50
Who typically builds higher-level software tools to solve the critical-section problem for application programmers?
Operating-system designers.
51
What is considered the simplest of the higher-level software tools for solving the critical-section problem?
The mutex lock.
52
The term 'mutex' is short for what phrase?
Mutual exclusion.
53
What is the primary function of a mutex lock?
To protect critical sections and thus prevent race conditions.
54
What must a process do before entering a critical section when using a mutex lock?
It must acquire the lock.
55
What must a process do when it exits a critical section protected by a mutex lock?
It must release the lock.
56
The function that obtains a mutex lock is typically called _____.
acquire()
57
The function that lets go of a mutex lock is typically called _____.
release()
58
A simple mutex lock implementation uses a boolean variable, often named _____, to indicate if the lock is free.
available
59
What is the result of a process calling `acquire()` on a mutex lock that is currently available?
The call succeeds, and the lock is then considered unavailable.
60
What happens to a process that attempts to acquire a mutex lock that is already held by another process?
The process is blocked until the lock is released.
61
The implementation of the `acquire()` and `release()` functions for a mutex lock must be performed as an _____ unit.
atomic (or uninterruptible)
62
How can the atomicity required for `acquire()` and `release()` operations be achieved?
It can be achieved via hardware support.
63
In the simple implementation `acquire() { while (!available) ; available = false; }`, what is the purpose of the `while` loop?
To wait until the lock becomes available (busy waiting).
64
What is the primary action of the simple `release()` function?
It sets the `available` variable to true.
65
What is the main disadvantage of a mutex lock implementation that uses a `while (!available)` loop?
It requires busy waiting.
66
When one process is in its critical section, any other process trying to enter must loop continuously in the call to `acquire()`. This is known as _____.
busy waiting
67
Why is busy waiting particularly problematic in a single-core multiprogramming system?
It wastes CPU cycles that another process could have used productively.
68
What is the term for a mutex lock where a process 'spins' in a loop while waiting for the lock to become available?
A spinlock.
69
What is the primary advantage of a spinlock over a locking mechanism that blocks processes?
No context switch is required when a process must wait on a lock.
70
Why is avoiding a context switch sometimes advantageous?
Because a context switch may take a considerable amount of time.
71
On what type of systems are spinlocks considered a preferred choice for locking under certain circumstances?
On multicore systems.
72
Under what condition is a spinlock particularly effective on a multicore system?
When a lock is expected to be held for only a short duration.
73
Where are spinlocks widely used in modern computing?
In many operating systems on modern multicore computing systems.
74
What more robust synchronization tool can behave like a mutex lock but also provide more sophisticated synchronization?
A semaphore.
75
A semaphore is an integer variable that is accessed only through what two atomic operations, apart from initialization?
wait() and signal().
76
The semaphore operation `wait(S)` decrements the semaphore S, but only after ensuring that _____.
S is greater than 0
77
The semaphore operation `signal(S)` performs what action on the semaphore S?
It increments the value of S (S++).
78
A critical requirement for all modifications to a semaphore's value in `wait()` and `signal()` is that they must be executed _____.
atomically
79
What does it mean for a semaphore modification to be atomic?
When one process modifies the semaphore value, no other process can simultaneously modify that same semaphore value.
80
In the `wait(S)` operation, which two parts must be executed without interruption as a single unit?
The testing of the integer value of S (S ≤ 0) and its possible modification (S--).
81
What are the two main types of semaphores?
Binary semaphores and counting semaphores.
82
A _____ semaphore is an integer whose value can only range between 0 and 1.
binary
83
A binary semaphore is functionally similar to what other synchronization tool?
A mutex lock.
84
On systems that do not provide mutex locks, what can be used instead to provide mutual exclusion?
Binary semaphores.
85
A _____ semaphore is an integer whose value can range over an unrestricted domain (or from 0 to N).
counting
86
What is a primary use case for counting semaphores?
To control access to a finite number of resources.
87
When using a counting semaphore to manage a set of resources, what should its initial value be?
The number of resources available.
88
To use a resource controlled by a counting semaphore, a process must perform a _____ operation on the semaphore.
wait()
89
Performing a `wait()` operation on a resource-counting semaphore has what effect on its value?
It decrements the semaphore's value.
90
When a process releases a resource controlled by a counting semaphore, it performs a _____ operation.
signal()
91
Performing a `signal()` operation on a resource-counting semaphore has what effect on its value?
It increments the semaphore's value.
92
When a counting semaphore used for resource management reaches a value of 0, what does this signify?
All available resources are currently being used.
93
What happens to a process that performs a `wait()` operation on a counting semaphore whose value is 0?
The process will be blocked until the semaphore value becomes greater than 0.
94
What is the general structure of a process using a semaphore to access a limited resource?
An infinite loop containing `wait()`, followed by resource use, followed by `signal()`.
95
Besides mutual exclusion, semaphores can be used to solve various _____ problems.
synchronization
96
Consider two processes, P1 and P2. How can a semaphore ensure that statement S2 in P2 executes only after statement S1 in P1 has finished?
By having P1 and P2 share a common semaphore initialized to 0.
97
To enforce that S1 runs before S2, what should the initial value of the shared semaphore `synch` be?
0
98
To enforce that S1 runs before S2, process P1 should execute `S1;` followed by what semaphore operation?
`signal(synch);`
99
To enforce that S1 runs before S2, process P2 should execute what semaphore operation before `S2;`?
`wait(synch);`
100
Why does initializing `synch` to 0 ensure P2 waits for P1?
Because P2's call to `wait(synch)` will block until P1 executes `signal(synch)` after S1 is complete.
101
What is a significant risk when programming with semaphores?
Using them incorrectly can result in subtle and difficult-to-detect errors.
102
What happens if a programmer incorrectly interchanges the order of `wait()` and `signal()` when implementing mutual exclusion?
The mutual-exclusion requirement is violated, and several processes may be in their critical sections simultaneously.
103
Which order of operations, `signal(mutex); ... wait(mutex);`, violates mutual exclusion?
Calling `signal(mutex)` before the critical section and `wait(mutex)` after it.
104
What higher-level synchronization construct was proposed to address the error-prone nature of semaphores?
Monitors.
105
Monitors are described as language-specific _____ constructs.
synchronization
106
What is the fundamental guarantee that a monitor provides?
Only one process may be active within the monitor at any given time.
107
At what level of the system must monitors be implemented?
At the compiler or language level.
108
Whose responsibility is it to enforce a monitor's mutual exclusion property?
The compiler.
109
In the monitor construct, where is the critical section of code placed?
Inside the monitor.
110
What is the first step a process must take to execute a critical section protected by a monitor?
The process must enter the monitor.
111
What happens if a process attempts to enter a monitor that is already occupied by another process?
The process must wait in an entry queue.
112
What event allows the next waiting process to enter a monitor?
The process currently inside the monitor leaves.
113
The diagram of a monitor shows processes waiting to enter in a structure called the _____.
entry queue
114
Who determines the specific implementation details of how a monitor enforces mutual exclusion?
The compiler, language, or system.
115
The behavior of a monitor, where only one process can be inside at a time, is similar to what other concept in synchronization?
A critical section.
116
When a process finishes its task inside a monitor, what must it do?
It must leave the monitor, allowing another process to enter.