[Win32 Thread] CreateMutex
CreateMutex
Win32 CreateMutex函式的原型如下:
HANDLE WINAPI CreateMutex(
__in_opt LPSECURITY_ATTRIBUTES lpMutexAttributes,
__in BOOL bInitialOwner,
__in_opt LPCTSTR lpName
); HANDLE hMutex;lpMutexAttributes: 指向安全屬性的指標 default security attributes
bInitialOwner: 初始化互斥物件的所有者 initially not owned
lpName: 指向互斥物件名的指標 unnamed mutex
hMutex = CreateMutex(NULL, false, "LOCK");宣告
WaitForSingleObject(hMutex, INFINITE);Lcok
ReleaseMutex(hMutex);Unlock
通常WaitForSingleObject與ReleaseMutex會用再同一個function內,一個放開頭,一個放結尾。
Comments
Post a Comment