chapter 32 - common concurrency problems Flashcards

(10 cards)

1
Q

what is a deadlock

A

A situation where two or more threads wait on each other to release resources, and none can proceed

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

Give an example of a deadlock

A

Thread 1 holds Lock A, waits for Lock B; Thread 2 holds Lock B, waits for Lock A

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

What are the 4 Coffman Conditions for deadlock? - deadlock only occurs if all four of these are hold

A

-Mutual Exclusion
-Hold and Wait
-No Preemption
-Circular Wait

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

how does circular wait work

A

use a global ordering for acquiring locks - always acquire locks in a specific order

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

How does hold-and-wait work

A

A process is holding one resource and waiting to acquire another

Thread A holds Lock1, and wants Lock2 (which is held by another thread)

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

How does trylock help prevent deadlock?

A

it lets a thread skip or back off if it can’t acquire a lock, avoiding wait cycles

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

What problem can trylocks cause and how to fix it?

A

Livelock - acquire a lock without blocking. If the lock is taken, it fails instead of waiting

solved by adding random delays or backoff strategies

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

Why is avoiding mutual exclusion effective?

A

It removes the need for locks, and thus the potential for deadlocks

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

complex dependencies

A

Each thread depends on multiple locks
circular dependency and deadlock risk

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

encapsulation conflicts with locking

A

Hiding implementation details, but lock order often depends on those details

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