32. Common concurrency problems Flashcards

1
Q

What are two most common concurrency problems?

A

Atomicity violation and order violation.

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

What four conditions must be met for a deadlock?

A
  1. Mutual exclusion: Threads claim exclusive control of resources that they require (e.g., a thread grabs a lock).
  2. Hold-and-wait: Threads hold resources allocated to them (e.g.,locks that they have already acquired) while waiting for additional resources (e.g., locks that they wish to acquire).
  3. No preemption: Resources (e.g., locks) cannot be forcibly removed from threads that are holding them.
  4. Circular wait:There exists a circular chain of threads such that each thread holds one or more resources (e.g., locks) that are being requested by the next thread in the chain.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What can we do to prevent curicular wait?

A

Total or partial ordering

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

What can we do to avoid hold-and-wait?

A

Acquire all locks at once, atomically (through additional lock).

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

How can we avoid no preemtpion?

A

By using more advanced interfaces that don’t get stuck waiting for lock such as pthread_mutex_trylock() .

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

How can we avoid mutual exclusion?

A

By not using mutual exclusion. This is accomplished by using wait-free and lock-free data structures, such as those that use atomic machine instructions (test-and-set, compare-and-swap and so on).

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