Concurrency: ThreadInteraction & Deadlocks Flashcards

1
Q

What are 2 types of synchronization?

A
  • Mutual Exclusion (Wechselseitiger Ausschluss), allows max 1 thread to access the shared resource at once
  • Condition Synchronization (Zustandssynchronisation): thread waits for a specific condition, another thread executes methods to produce this condition
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What’s the purpose of the “synchronized” statement?

A

To mark critical sections within the code in order to guarantee mutual exclusion

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

What are the 2 possible forms of the synchronized statement?

A
  • Synchronized Method

- Synchronized Block

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

What’s the purpose of a monitor?

A

A monitor acts as a Lock for exclusive access right. Max. 1 thread can own the monitor.

  1. Acquire monitor at start of synchronized block
  2. Within synchronized block
  3. Release monitor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

If we choose to call a synchronized block from another synchronized block, which case is less risky:

a) use the same monitor object
b) use different monitor object

A

a) use the same monitor object won’t block a thread. If it’s 2 different monitors there’s the risk of a deadlock

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

What’s the purpose of condition synchronization?

A

To control the cooperation of threads.

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