Process Synchronisation Flashcards

1
Q

What is the critical section problem?

A

When multiple processes/threads access shared data simultaneously, leading to race conditions (unpredictable results)

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

Solution Requirements for the Critical Section Problem

A
  • Mutual Exclusion: Only one process in CS at a time
  • Progress: No process outside CS should block others
  • Bounded Waiting: No process waits forever
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does Peterson’s algorithm work?

A

Uses turn and flag[2] variables to ensure mutual exclusion for two processes

flag[i] = true;
turn = j;
while (flag[j] && turn == j);
flag[i] = false;

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

What is a mutex lock?

A

A binary lock [acquire()/release()] that ensures only one process enters critical section

acquire() {
while (!available);
available = false;
}
release() {
available = true;
}

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

What is a semaphore and how does it differ from a mutex?

A

An integer variable with atomic “wait()” (P) and “signal()” (V) operations:
- Counting Semaphore: Tracks multiple resources
- Binary Semaphore: Acts like a mutex (0 or 1)

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

How does a semaphore avoid busy waiting?

A

Uses blocking/wakeup:

wait(S) {
S–;
if (S < 0) { block(); }
}
signal(S) {
S++;
if (S <= 0) { wakeup(P); }
}

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

How do semaphores solve the producer-consumer problem?

A

Use three semaphores:
1. mutex (1 for CS access)
2. empty (n for empty slots)
3. full (0 for filled slots)

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

Solution for Dining Philosophers

A

Allow only 4 philosophers to eat or make one pick right-first

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

What causes deadlock in the dining philosophers problem?

A

All philosophers simultaneously pick up their left chopstick, waiting indefinitely for the right one.

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

Deadlock vs Starvation

A
  • Deadlock: Two+ processes wait forever for each other’s resources
  • Starvation: A process is indefinitely denied resources
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a monitor in synchronisation?

A

A high-level construct where methods auto-synchronise (only 1 thread executes at a time)

monitor Account {
int balance;
method deposit() {…}
}

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

What’s a monitor?

A

A class-like structure ensuring only one thread executes its methods at a time
+ No manual lock management
- Less flexible than semaphores

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