Настолько умная что я туплю :-) Читаю по ссылке
"A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned."
Внизу страницы переход на страницу "Using Mutex Objects"
Там:
while( dwCount < 20 )
{
dwWaitResult = WaitForSingleObject(
ghMutex, // handle to mutex
INFINITE); // no time-out interval
switch (dwWaitResult)
{
// The thread got ownership of the mutex
case WAIT_OBJECT_0:
__try {
// TODO: Write to the database
printf("Thread %d writing to database...\n",
GetCurrentThreadId());
dwCount++;
}
__finally {
// Release ownership of the mutex object
if (! ReleaseMutex(ghMutex))
{
// Handle error.
}
}
break;
// The thread got ownership of an abandoned mutex
// The database is in an indeterminate state
case WAIT_ABANDONED:
return FALSE;
}
}
У меня тупой вопрос, в какой момент ghMutex захватывается (переходит из signaled в nonsignaled состояние)?
Где четкое указание, что WaitForSingleObject() переводит mutex в занятое сотояние для других процессов, а
вызвавший ее процесс ексклюзивно получит WAIT_OBJECT_0 и можно безопасно проводить действия до ReleaseMutex()?
На странице WaitForSingleObject function
https://msdn.micro …sktop/ms687032(v=vs.85).aspx
такого нет.