Mutex: Difference between revisions
Content added Content deleted
(Some explanation of Ada implementation) |
(→{{header|C}}: posix mutex) |
||
Line 68:
It is also possible to implement mutex as a monitor task.
=={{header|C}}==
===Win32===
{{works with|Win32}}
To create a mutex operating system "object":
<
HANDLE hMutex = CreateMutex(NULL, FALSE, NULL);
</
To lock the mutex:
<
WaitForSingleObject(hMutex, INFINITE);
</
To unlock the mutex
<
ReleaseMutex(hMutex);
</
When the program is finished with the mutex:
<
CloseHandle(hMutex);
</
===POSIX===
{{works with|POSIX}}
Creating a mutex:
<c>#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;</c>
Locking:
<c>pthread_mutex_lock(&mutex);</c>
Unlocking:
<c>pthread_mutex_unlock(&mutex);</c>
=={{header|C++}}==
{{works with|Win32}}
|