chapter 32 - common concurrency problems Flashcards

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 can hold-and-wait work

A

Acquire all locks at once using an extra lock that serializes locks - L1, så L2 så L3 osv

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 -> 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

How can mutual exclusion be avoided?

A

Use lock-free structures with atomic operations like Compare-And-Swap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
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
10
Q

complex dependencies

A

easy to to make cross-dependencies that makes a cycle where each parts wait for eachother

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

encapsulation conflicts with locking

A

Object-oriented encourages 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
12
Q

why does deadlocks occur

A
  • complex dependencies
  • encapsulation conflicts with locking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly