Mutex: Difference between revisions

Content added Content deleted
m (→‎{{header|Java}}: Adding a throws for compilability)
m (→‎Win32: whitespace)
Line 69: Line 69:
{{works with|Win32}}
{{works with|Win32}}
To create a mutex operating system "object":
To create a mutex operating system "object":
<lang c>HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);</lang>
<lang c>
HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);
</lang>
To lock the mutex:
To lock the mutex:
<lang c>WaitForSingleObject(hMutex, INFINITE);</lang>
<lang c>
WaitForSingleObject(hMutex, INFINITE);
</lang>
To unlock the mutex
To unlock the mutex
<lang c>
<lang c>ReleaseMutex(hMutex);</lang>
ReleaseMutex(hMutex);
</lang>
When the program is finished with the mutex:
When the program is finished with the mutex:
<lang c>
<lang c>CloseHandle(hMutex);</lang>
CloseHandle(hMutex);
</lang>


===POSIX===
===POSIX===