Concurrency: ThreadInteraction & Deadlocks Flashcards
What are 2 types of synchronization?
- 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
What’s the purpose of the “synchronized” statement?
To mark critical sections within the code in order to guarantee mutual exclusion
What are the 2 possible forms of the synchronized statement?
- Synchronized Method
- Synchronized Block
What’s the purpose of a monitor?
A monitor acts as a Lock for exclusive access right. Max. 1 thread can own the monitor.
- Acquire monitor at start of synchronized block
- Within synchronized block
- Release monitor
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) use the same monitor object won’t block a thread. If it’s 2 different monitors there’s the risk of a deadlock
What’s the purpose of condition synchronization?
To control the cooperation of threads.