Studying example from MSDN article Using Mutex Objects some questions arise about mutex entity.
Here are experimentally proved suggestions:
Some create mutex via CreateMutex while having ERROR_ALREADY_EXISTS
Pic 1. Running 10 of these programs:
Example sources are here...
Here are experimentally proved suggestions:
- Mutexes are like files, open and create them with CreateMutex, close with CloseHandle (for files you use CreateFile, CloseHandle)
- Unnamed mutex is like critical section
- Mutexes are deleted after CloseHandle when no application currently have them opened
HANDLE hSome programs create h = 0x3c, some h = 0x44
main(){
h = CreateMutex("Global\\SuperMutex")
CreateThread(WriteToDatabase)
CloseHandle(h)
}
WriteToDatabase()
{
WaitForSingleObject(h)
ReleaseMutex(h)
}
Some create mutex via CreateMutex while having ERROR_ALREADY_EXISTS
Pic 1. Running 10 of these programs:
Example sources are here...