Semaphore drawbacks
How can Monitors be an alternative to semaphores?
How does the monitor sync data?
The process of a thread entering the monitor
Thread waiting on a condition in a monitor
Why is a monitor good?
What does a monitor encapsulate?
How does a monitor ensure ME?
Each monitor has a lock and condition variable connected to it.
Condition variable in monitors
Wait() condition variable
Pulse() condition variable
PulseAll() condition variable
What is a condition variable?
Thread or Monitor? Active and passive objects
Mutual Exclusion through monitor?
In what way do monitors support both mutual exclusion & condition sync?
How do waiting threads work in a monitor queue?
What is condition synchronization?
How does condition synchronization work in monitors?
What is the relationship between condition sync and condition variables?
What are the monitor methods in C#?
How is a monitor structured in C#?
object monitorObj = new object();
public double Method()
{
Monitor.Enter(monitorObj);
try
{
//critical section code
}
finally
{
Monitor.Exit(monitorObj);
}
}
}
Condition variables vs mutex
C# lock/Monitor example
lock(lockObj) //same as .Enter
{
while(IsFull)
{
//thread blocks
Monitor.Wait(lockObj);
}
//More code
Monitor.Pulse(lockObj);
} //same as .Exit = the lock releases here