Monitor as synchronization on Windows

2019-04-17 17:11发布

问题:

Is there any implementation of monitor on Windows? I didn't see any win32 API references Monitor.

回答1:

Windows does not have a monitor implementation of its own. However, Vista introduced Condition Variables and Slim Reader/Writer locks, which can be used together to create a monitor implementation.



回答2:

Yes it does. Windows has monitors and monitor functions: EnterCriticalSection is similar to POSIX pthread_mutex_lock (enters the monitor). LeaveCriticalSection is similar to POSIX pthread_mutex_unlock (leaves monitor).

SleepConditionVariableCS similar to POSIX pthread_cond_wait.

WakeConditionVariable ... POSIX pthread_cond_signal.

WakeAllConditionVariable ... POSIX pthread_cond_broadcast

All these funcions you can find here:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms686360(v=vs.85).aspx