Multithreaded Programming Guide

Acquiring a Mutex

Use mutex_lock(3C) to lock the mutex pointed to by mp. When the mutex is already locked, the calling thread blocks until the mutex becomes available. Blocked threads wait on a prioritized queue. For POSIX threads, see pthread_mutex_lock Syntax.

mutex_lock Syntax

#include <thread.h>

int mutex_lock(mutex_t *mp);

mutex_lock Return Values

mutex_lock() returns 0 if successful. When any of the following conditions is detected, mutex_lock() fails and returns the corresponding value.



mp points to an illegal address.



The mutex is already locked and is owned by the calling thread.