Mutex: Difference between revisions

Content deleted Content added
→‎{{header|C}}: posix mutex
Line 95: Line 95:
<c>#include <pthread.h>
<c>#include <pthread.h>


pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;</c>
int success = pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;</c>


Locking:
Locking:


<c>pthread_mutex_lock(&mutex);</c>
<c>int success = pthread_mutex_lock(&mutex);</c>


Unlocking:
Unlocking:


<c>pthread_mutex_unlock(&mutex);</c>
<c>int success = pthread_mutex_unlock(&mutex);</c>

Trying to lock (but do not wait it can't)

<c>int success = pthread_mutex_trylock(&mutex);</c>


=={{header|C++}}==
=={{header|C++}}==