Let it say that I call CreateMutex.
HANDLE h; h=CreateMutex(NULL, TRUE, NULL); waitforsingleobject(h, INFINITE); ////Random Code ReleaseMutex(h);
Assuming I have multiple threads, does the first thread to access the createmutex function essentially block all other threads from the random code section until the mutex release is called correctly?
This is not so because you created an unnamed mutex (the third parameter is the name). Assuming that the sample code is executed in several threads, each thread will create a new unnamed mutex and immediately gain access to the critical section (Random Code), because they are only waiting for their mutex.
, h , , CreateMutex CreateMutex ( ). CreateMutex .
, , .
.
, , , . , .
, mutex , , . , , .
, , WaitForSingleObject .
, , ownerip term terminated, .
, ReleaseMutex mutex, ownerip. , RAII ( , return ReleaseMutex, ).
-, , , CloseHandle MutexHandle.
, , . : " Mutex"
. :
Only if the same mutex reference is used for all threads / processes. You do not share it, you create it every time. You will need to name it so that they all get the same mutex so that your code works.
Source: https://habr.com/ru/post/1794667/More articles:VS2010 extension to display hover type definition - visual-studioIIS7 404 Errors - asp.netVOIP C ++ Programming - c ++jQuery: an easy way to fire the "mousestop" event - jqueryAndroid ImageView gets scaled image on screen - androidHow to get raw raster image sizes in ImageView? - androidHow can I reduce Mongo db by averaging old data - databaseСамый простой способ реализовать перенаправление SMB для Windows? - windowsJavaScript: do not unload a document until the completion of HttpRequest - javascriptDatabinding and INotifyPropertyChanged not working - windows-phone-7All Articles