Chapter 6+7 Flashcards

(34 cards)

1
Q

Why can disabling interrupts frequently affect system clock?

A

Clock updates occur via timer interrupts. Disabling interrupts prevents clock updates causing time drift. Minimize by keeping interrupt-disabled periods very short.

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

What is busy waiting and what other waiting types exist?

A

Busy waiting: continuously checking condition in loop wasting CPU. Other types: blocking (process sleeps) interrupt-driven waiting. Can’t avoid entirely but can minimize.

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

Why are spinlocks inappropriate for single-processor but good for multiprocessor?

A

Single-processor: spinning process prevents lock holder from running. Multiprocessor: other cores can run lock holder while one core spins.

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

How can non-atomic wait() and signal() violate mutual exclusion?

A

Two processes could read semaphore value simultaneously both see 1 both decrement creating race condition allowing both into critical section.

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

How does binary semaphore implement mutual exclusion among n processes?

A

Initialize semaphore to 1. Each process calls wait() before critical section signal() after. Only one process can have semaphore at 0.

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

What race condition exists in banking deposit/withdraw scenario?

A

Both read same balance concurrently perform calculations write back results. One update lost. Solution: use locks around entire read-modify-write sequence.

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

What data has race condition in concurrent stack operations?

A

The ‘top’ variable and stack array elements. Multiple threads can modify top simultaneously corrupting stack state.

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

How to fix stack race condition?

A

Move acquire()/release() calls to surround entire operation in push/pop. Fix is_empty() to also use locking or make it atomic.

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

Are there race conditions in parallel array summing code?

A

No race conditions. Each iteration synchronizes before next begins. Each element written by only one processor at each level.

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

Does compare-and-compare-and-swap idiom work for spinlocks?

A

Yes it works correctly. First check avoids unnecessary compare_and_swap calls when lock unavailable improving performance on bus traffic.

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

What three requirements must Dekker’s algorithm satisfy?

A

Mutual exclusion: only one in critical section. Progress: processes not in critical section can’t prevent entry. Bounded waiting: waiting time is limited.

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

Where are memory barriers needed in Dekker’s algorithm?

A

Before flag assignments and after turn assignments to ensure proper memory ordering preventing reordering optimizations.

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

How to implement acquire() with compare_and_swap?

A

while(compare_and_swap(&mutex->available 0 1) != 0); // spin until successfully change 0 to 1

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

How to implement release() with compare_and_swap?

A

mutex->available = 0; // simply set back to available state

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

When is spinlock better than mutex lock?

A

Short duration locks: spinlock avoids context switch overhead. Multiprocessor systems where other cores can run while spinning.

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

When is mutex lock better than spinlock?

A

Long duration locks: sleeping threads don’t waste CPU cycles. Single processor systems. When thread may sleep while holding lock.

17
Q

Which is more efficient: mutex or atomic operations for hit counter?

A

Atomic operations more efficient. Single instruction vs multiple instructions for mutex acquire/release plus no context switch risk.

18
Q

How can semaphores limit server connections?

A

Initialize semaphore to N (max connections). Each new connection calls wait() on semaphore. Connection close calls signal(). Blocks when N connections reached.

19
Q

How is deadlock possible in dining philosophers?

A

Each philosopher picks up left fork then waits for right fork. If all pick up left simultaneously all wait for right fork creating circular wait deadlock.

20
Q

Why can’t process hold spinlock while acquiring semaphore in Linux?

A

Spinlock disables preemption. If semaphore unavailable process would spin forever since it can’t be scheduled out to let semaphore holder run.

21
Q

What is difference between spinlock and blocking lock?

A

Spinlock: process actively waits consuming CPU cycles but no context switch. Blocking: process sleeps releases CPU requires context switch.

22
Q

How does atomic compare_and_swap work?

A

Atomically compares memory location with expected value. If equal updates with new value returns old value. If not equal returns current value unchanged.

23
Q

What is critical section problem?

A

Ensuring only one process executes in critical section at time while allowing progress and preventing indefinite postponement.

24
Q

What are Peterson’s algorithm requirements?

A

Mutual exclusion progress and bounded waiting using only shared memory and no special hardware instructions.

25
How does semaphore differ from mutex?
Semaphore: counting synchronization primitive can allow multiple resources. Mutex: binary lock for mutual exclusion only.
26
What is race condition?
Multiple processes access shared data concurrently and outcome depends on timing of execution leading to inconsistent results.
27
How do memory barriers prevent reordering?
Compiler and processor optimizations can reorder instructions. Memory barriers ensure specific ordering of memory operations for correctness.
28
What is test-and-set instruction?
Atomic instruction that reads memory location and sets it to 1 returning original value. Used to implement locks atomically.
29
How does monitor solve synchronization problems?
High-level synchronization construct with mutual exclusion built-in and condition variables for waiting and signaling.
30
What are advantages of hardware synchronization instructions?
Atomic execution prevents race conditions. More efficient than software solutions. Enable lock-free programming.
31
What is priority inversion problem?
Low priority process holds resource needed by high priority process while medium priority process prevents low priority from releasing resource.
32
How does priority inheritance solve priority inversion?
Temporarily boost priority of low priority process holding resource to priority of high priority process waiting for it.
33
What is lock-free programming?
Using atomic operations instead of locks to coordinate between threads avoiding deadlock and priority inversion issues.
34
How do condition variables work with mutexes?
Thread acquires mutex checks condition releases mutex and waits. When signaled reacquires mutex and rechecks condition.