Mod 4: Monitors and condition synchronization Flashcards
What is a monitor?
(1) Class, object or module providing more structure than a semaphore does
(2) Structured way of combining data and synchronization
(3) Provides all benefits of encapsulation of data
(4) Synchronization technique
What do a monitor do?
(1) Guarantes ME,
(2) encapsulate data and operations
(3) encapsulate thread synchronization using conditional synchronization
Using which methods is conditional syncrhonization achieved? (in Java)
(1) Wait( )
(2) Notify( )
(3) NotifyAll( )
What does all monitors have?
(1) Lock object (Mutex)
(2) condition variable
Every monitor also have a waiting thread (blocked threads)
What are the two types of synchronization, and which does a monitor supports?
(1) Mutual Exclusion,
(2) Condition Synchronization
Monitor supports both type.
How does a monitor support conditional synchronization?
Explicitly via condition variables
How does a monitor support mutual exclusion?
A single global lock (on of the items associated with a monitor) ensure mutex for all operations in the monitor
How do you create a monitor in java?
Using the synchronized key word the region (eg method) becomes a monitor
What are the steps when a thread uses a monitor?
(1) Enter the monitor, waiting for access
(2) Aquire monitor
(3) Owning monitor (locks door)
(4) Release monitor (unlock door)
(5) Exit the monitor
What is a suspended thread?
A thread waiting for a condition to be true / to be allowed to continue its path of execution
For what does a monitor use a conditional variable?
To suspend and wake up threads
What is the difference between a condition variable and a condition synchronization?
A condition variable is synchronization mechanisms that allow a thread to wait for a specific condition to become true, while condition synchronization refers to the coordination of threads based on some condition
What are the methods each condition variable often have?
(1) Wait ( )
(2) Signal ( ) or notify
(3) SignalAll ( ) or notifyAll
How can a thread block itself and why would it want to?
By calling wait( ), in order to wait for a specific condition to become true
What is the difference between a mutex (or binary semaphore) and conditional variable?
Mutex / BS implements synchronization by controlling
thread access TO data, condition variable allows threads to synchronize based on the actual value of the data