To call Monitor.Wait(obj) or Monitor.Pulse(obj) it's necessary first to have entered the monitor, via lock(obj) or Monitor.Enter(obj). Why does the API require this?
Thread synchronization: Wait and Pulse demystified hints at something about conditional variables etc., but I don't see why I'd want that to always be used.
I mean if it's just that the implementation depends on the lock being acquired to do the work of Wait or Pulse, why not just implement that internally as a part of them? Why not decouple Wait and Pulse entirely from the other behaviour in Monitor and let the developer use these functions as they want? It seems like a pointless burden on the developer, but is there a good reason for it to be like this?
To be more specific, Monitor.Wait(obj) throws SynchronizationLockException if "Wait is not invoked from within a synchronized block of code". Monitor.Pulse(obj) throws SynchronizationLockException if "the calling thread does not own the lock for the specified object".
lockis implemented usingMonitorclass and not the other way around" or "why to release a lock withWait/Pulseone need to acquire the lock first withlockorEnter"? Or you asking more about why those exist at all like stackoverflow.com/questions/1559293/…?Waitto do so people can try to clarify that. (Side note you obviously know that "EDIT:" should not be added to post - avoid doing so unless you have some particular statement to make)