CS2005 - Lecture 11 - Synchronisation Flashcards

(28 cards)

1
Q

What is the critical section problem in operating systems?

A

The critical section problem involves ensuring that when one process is executing in its critical section, no other process can execute in their critical section simultaneously.

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

Why does data inconsistency occur in concurrent systems?

A

Data inconsistency arises when multiple processes access and modify shared data concurrently without proper synchronisation mechanisms.

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

List the three requirements for a solution to the critical section problem.

A

Mutual Exclusion: Only one process in the critical section at a time; Progress: A decision about entry cannot be postponed indefinitely; Bounded Waiting: There is a bound on the number of times other processes can enter before one gets its turn

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

What is Peterson’s solution used for?

A

It’s a software algorithm to solve the critical section problem for two processes using shared flags and a turn variable.

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

What are the roles of flag[] and turn in Peterson’s solution?

A

flag[i] indicates that process Pi wants to enter the critical section; turn indicates whose turn it is. Mutual exclusion is achieved by checking both conditions.

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

What is a spinlock?

A

A spinlock is a lock that causes a thread to busy wait in a loop while trying to acquire it. It consumes CPU cycles while waiting.

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

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

A

A semaphore is a synchronisation tool that can manage access by multiple processes to a shared resource. Unlike a mutex, semaphores can allow more than one process in the critical section (counting semaphores).

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

Differentiate between binary and counting semaphores.

A

Binary Semaphore: Can be 0 or 1, similar to mutex; Counting Semaphore: Value can range over an unrestricted domain

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

What is a race condition?

A

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

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

What issues do semaphores help resolve in process synchronisation?

A

Semaphores help avoid race conditions, ensure mutual exclusion, enforce execution order, and eliminate busy waiting with blocking mechanisms.

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

Describe the concept of a monitor in synchronisation.

A

A monitor is a high-level synchronisation construct that encapsulates shared variables and procedures, ensuring only one process executes in it at a time.

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

Name two classic synchronisation problems discussed in the lecture.

A

Bounded Buffer (Producer-Consumer); Dining Philosophers

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

What concept is illustrated in Diagram1?

A

The Producer-Consumer problem using a bounded buffer, where the producer generates data and the consumer uses it.

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

In Diagram1, what does the buffer represent?

A

A fixed-size shared queue used to store items produced before they are consumed.

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

What does Diagram2 depict in the context of the producer?

A

The producer loop checks if the buffer is full, then adds an item and updates the in index and counter.

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

What does the label ‘in = 3, counter = 3’ mean in Diagram3?

A

It shows that the buffer currently holds 3 items, and the next produced item will go at index 3.

17
Q

What does the consumer do in Diagram4’s code block?

A

It waits if the buffer is empty, consumes an item at out, then increments out and decrements counter.

18
Q

What is the significance of ‘out = 1’ in Diagram5?

A

It indicates the consumer just removed the first item and will next read from index 1.

19
Q

What race condition is illustrated in Diagram6?

A

The race condition on the counter variable due to unsynchronised access by producer and consumer.

20
Q

What does Diagram7 represent?

A

Peterson’s Algorithm for two processes ensuring mutual exclusion using flags and a turn variable.

21
Q

What is the role of ‘acquire lock’ and ‘release lock’ in Diagram8 and Diagram9?

A

They represent entry and exit for the critical section using a lock mechanism, requiring busy wait.

22
Q

What do the wait() and signal() operations do in Diagram10?

A

wait() decrements the semaphore and may block the process; signal() increments it and may wake a waiting process

23
Q

What ordering does Diagram11 enforce using semaphores?

A

It enforces S₂ to execute only after S₁ completes, using signal() and wait().

24
Q

How is busy waiting implemented in Diagram12?

A

The wait() function uses a while(S <= 0); loop, which continuously checks until the semaphore is available.

25
What issue is depicted in Diagram13 with P0 and P1?
Deadlock, where each process holds one semaphore and waits on the other.
26
How does Diagram14 solve the producer-consumer problem using semaphores?
It uses mutex, empty, and full semaphores to synchronise producer and consumer without busy waiting.
27
What does Diagram15 illustrate?
The Dining Philosophers problem, showing how philosophers need two chopsticks to eat.
28
What is the purpose of the structure shown in Diagram16 and Diagram17?
It's a monitor, a construct that allows only one process to execute inside it, providing synchronised access to shared data.