Chapter 5 Flashcards

(41 cards)

1
Q

What is process synchronization?

A

A mechanism that ensures orderly execution of cooperating processes that share data to prevent inconsistencies.

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

Why is synchronization necessary?

A

Because concurrent access to shared data can cause race conditions, leading to inconsistent results.

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

What is a race condition?

A

When two or more processes access shared data simultaneously and the final result depends on the order of execution.

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

What is a critical section?

A

A section of code where shared resources are accessed or modified; only one process should execute it at a time.

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

What is the critical section problem?

A

The challenge of designing a protocol so that no two processes execute in their critical sections simultaneously.

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

What are the three requirements for a critical section solution?

A

Mutual Exclusion, Progress, and Bounded Waiting.

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

Define Mutual Exclusion.

A

If one process is executing in its critical section, no other process can enter its critical section.

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

Define Progress.

A

If no process is in its critical section, 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
9
Q

Define Bounded Waiting.

A

A limit must exist on how long a process waits before entering its critical section after requesting it.

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

What is a remainder section?

A

The part of the program outside the critical section.

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

What is Peterson’s Solution?

A

A software solution for mutual exclusion between two processes using shared variables flag[] and turn.

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

What are the shared variables in Peterson’s Solution?

A

flag[i] and turn, where flag[i]=true indicates process i wants to enter its critical section.

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

What ensures mutual exclusion in Peterson’s Solution?

A

Both processes cannot have turn at the same time; only one enters its critical section.

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

Does Peterson’s solution satisfy all three requirements?

A

Yes – it ensures mutual exclusion, progress, and bounded waiting.

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

What is a mutex lock?

A

A hardware/software mechanism that enforces mutual exclusion by allowing only one thread to hold the lock at a time.

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

What are the two operations of a mutex lock?

A

acquire() and release() (or pthread_mutex_lock() and pthread_mutex_unlock()).

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

What is busy waiting?

A

When a process repeatedly checks if a lock is available, wasting CPU time (also called a spinlock).

18
Q

Why are mutex locks called spinlocks?

A

Because a thread spins in a loop while waiting for the lock to be available.

19
Q

What is a semaphore?

A

An integer synchronization variable used to control access to shared resources through atomic operations wait() and signal().

20
Q

What is a binary semaphore?

A

A semaphore with values 0 or 1, equivalent to a mutex lock.

21
Q

What is a counting semaphore?

A

A semaphore that can take non-negative integer values, used to count available resources.

22
Q

What does wait(S) do?

A

Decrements the semaphore; if the result is negative, the process blocks itself.

23
Q

What does signal(S) do?

A

Increments the semaphore; if the result is <= 0, a blocked process is resumed.

24
Q

What is the drawback of simple semaphore implementation?

A

It can still cause busy waiting.

25
How can busy waiting in semaphores be removed?
By blocking the process instead of repeatedly checking (using process queues).
26
What is a deadlock?
A situation where two or more processes are waiting indefinitely for resources held by each other.
27
Provide an example of deadlock.
P0 waits for Q while holding S; P1 waits for S while holding Q; both block forever.
28
What is starvation?
When a process waits indefinitely even though resources are available, due to unfair scheduling.
29
How can starvation be prevented?
Using aging – increasing a process's priority the longer it waits.
30
What are classical synchronization problems?
Bounded Buffer, Readers-Writers, and Dining Philosophers.
31
What are the semaphores used in the bounded buffer problem?
mutex, full, and empty.
32
What is the bounded buffer problem?
A producer adds items to a buffer while a consumer removes them; both must not access it simultaneously.
33
What is the readers-writers problem?
Multiple readers can access shared data simultaneously, but writers need exclusive access.
34
What is the dining philosophers problem?
Five philosophers alternate between thinking and eating, competing for shared chopsticks (resources).
35
What causes deadlock in the dining philosophers problem?
All philosophers pick up their left chopstick simultaneously and wait for the right one.
36
What are three solutions to prevent deadlock in Dining Philosophers?
1. Allow only 4 philosophers at the table. 2. Pick up chopsticks only if both are available. 3. Odd/even philosophers pick up chopsticks in opposite order.
37
In Lab 4, what function acquires a semaphore?
sem_wait(&S[i]);
38
In Lab 4, what function releases a semaphore?
sem_post(&S[i]);
39
In Lab 4, what is the purpose of sleep(1) in the code?
To simulate eating/thinking time and demonstrate thread interleaving and deadlock behavior.
40
Why is using semaphores better than mutex locks for philosophers?
Semaphores can coordinate multiple resources (chopsticks) instead of one at a time.
41
What is the main learning outcome from Lab 4?
Understanding how semaphore synchronization prevents deadlock and enforces order among threads.