Unit 3: Process Synchronization and Deadlocks Flashcards

1
Q

What is process synchronization?

A

Process synchronization is necessary to manage concurrently executing processes that share common resources.

It helps to avoid conflicts and ensure data consistency.

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

What is a race condition?

A

A race condition occurs when multiple processes access and modify shared data concurrently, and the final outcome depends on the order of execution.

This can lead to unpredictable results.

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

How can incrementing and decrementing a shared counter lead to a race condition?

A

Incrementing (counter++) and decrementing (counter–) a shared counter by multiple processes can lead to an incorrect final value due to interleaving.

Interleaving refers to the overlapping execution of processes.

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

What is a critical section?

A

A critical section is a segment of code where a process accesses shared resources.

Proper management of critical sections is essential to avoid race conditions.

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

What is the goal of the critical section problem?

A

The goal of the critical section problem is to design protocols that allow processes to access shared resources safely and avoid race conditions.

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

What is mutual exclusion?

A

Mutual exclusion is a requirement for critical section solutions, ensuring that only one process can be in its critical section at a time.

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

What does progress mean in the context of critical sections?

A

Progress is a requirement, stating that if no process is in its critical section and some want to enter, the decision of who enters next cannot be postponed indefinitely.

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

What is bounded waiting?

A

Bounded waiting is a requirement, ensuring a limit on how many times other processes can enter their critical sections after a process has requested to enter its own.

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

What is Peterson’s solution?

A

Peterson’s solution is a software-based solution to the critical section problem for two processes, using shared flag and turn variables.

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

In Peterson’s solution, what does flag[i] = true indicate?

A

flag[i] = true indicates that process Pi is ready to enter the critical section.

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

What does the turn variable indicate in Peterson’s solution?

A

The turn variable indicates whose turn it is to enter the critical section.

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

What are atomic operations?

A

Atomic operations are hardware support instructions that are non-interruptible and help solve the critical section problem.

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

What does the test_and_set() instruction do?

A

test_and_set() atomically tests and sets a boolean value, returning the original value.

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

How can test_and_set() be used for mutual exclusion?

A

test_and_set() can be used with a shared lock variable to enforce mutual exclusion by busy-waiting until the lock is false.

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

What does the compare_and_swap() instruction do?

A

compare_and_swap() atomically compares a value with an expected value, and if they are equal, sets the value to a new value, returning the original value.

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

How can compare_and_swap() be used for mutual exclusion?

A

compare_and_swap() can be used with a shared lock variable to enforce mutual exclusion by busy-waiting until the lock is 0.

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

What is a semaphore?

A

A semaphore is a synchronisation tool (integer variable) accessed only through atomic wait() and signal() operations.

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

What does the wait() operation do in semaphore?

A

The wait(S) operation decrements the semaphore value S, and if S becomes non-positive, the process may be blocked.

19
Q

What does the signal() operation do in semaphore?

A

The signal(S) operation increments the semaphore value S, potentially waking up a blocked process.

20
Q

What is a counting semaphore?

A

A counting semaphore can have an integer value over an unrestricted domain, used for controlling access to a finite number of resources.

21
Q

What is a binary semaphore?

A

A binary semaphore can only have values 0 or 1, functioning similarly to a mutex lock for mutual exclusion.

22
Q

How can semaphores ensure order of execution?

A

Semaphores can ensure one statement (S1 in P1) happens before another (S2 in P2) by initialising a semaphore to 0 and using signal() after S1 and wait() before S2.

23
Q

What is deadlock?

A

Deadlock is a situation where two or more processes are blocked indefinitely, each waiting for a resource held by another process in the set.

24
Q

What is the mutual exclusion condition for deadlock?

A

Mutual exclusion is a condition for deadlock, where resources are non-sharable, and only one process can use a resource at a time.

25
What is the hold and wait condition for deadlock?
Hold and wait is a condition for deadlock, where a process holds at least one resource while waiting to acquire additional resources held by other processes.
26
What is the no preemption condition for deadlock?
No preemption is a condition for deadlock, where a resource can only be released voluntarily by the holding process after it has completed its task.
27
What is the circular wait condition for deadlock?
Circular wait is a condition for deadlock, where a cycle of processes exists, each waiting for a resource held by the next process in the cycle.
28
What is a resource-allocation graph?
A resource-allocation graph visually represents processes and resources, with request edges and assignment edges indicating resource needs and allocation.
29
How can a resource-allocation graph be used for deadlock detection?
In a resource-allocation graph with single instances per resource type, a cycle indicates a deadlock.
30
What is deadlock prevention?
Deadlock prevention aims to prevent deadlock by ensuring that at least one of the four necessary conditions cannot hold.
31
What is deadlock avoidance?
Deadlock avoidance allows the system to enter a potentially unsafe state but uses a priori information about resource needs to ensure that the system will never enter a deadlock state.
32
What is the Banker's algorithm?
The Banker's algorithm is a deadlock avoidance algorithm for multiple instances of resources, using the concepts of safe and unsafe states to decide whether to grant resource requests.
33
What is a safe state?
A system is in a safe state if there exists a sequence of all processes such that each process can acquire all its needed resources and then release them, thus avoiding deadlock.
34
What is an unsafe state?
A system in an unsafe state may lead to a deadlock, although it is not guaranteed.
35
What are deadlock detection algorithms used for?
Deadlock detection algorithms can be used to identify if a deadlock has occurred when deadlock avoidance is not employed.
36
What is one way to recover from deadlock?
One way to recover from deadlock is to abort one or more of the deadlocked processes.
37
What is another way to recover from deadlock?
Another way to recover from deadlock is to preempt resources from one or more of the deadlocked processes.
38
What is the bounded-buffer problem?
The bounded-buffer problem is a classic synchronisation problem between producers and consumers using a buffer of limited size.
39
How can semaphores be used for the bounded-buffer problem?
Semaphores (mutex, empty, full) can be used to synchronise producers and consumers in the bounded-buffer problem, ensuring correct access to the buffer.
40
What is the readers-writers problem?
The readers-writers problem is where multiple readers can access shared data simultaneously, but only one writer can access it at a time.
41
How can semaphores be used to solve the readers-writers problem?
Semaphores (rw_mutex, mutex, read_count) can be used to solve the readers-writers problem, controlling access for reading and writing.
42
What is the dining-philosophers problem?
The dining-philosophers problem is a classic synchronisation problem illustrating challenges in resource sharing and potential for deadlock.
43
How can semaphores be used in the dining-philosophers problem?
Semaphores (chopstick) can be used in an attempt to solve the dining-philosophers problem, and understand the potential for deadlock in a naive implementation.