mtx_init()

Initialize a mutex

Synopsis:

#include <threads.h>

int mtx_init( mtx_t *mtx,
              int type );

Arguments:

mutex
A pointer to the mtx_t object that you want to initialize.
Note: It's always safe, and typically faster, to assure that mutex is 32-bit aligned.
type
One of the following:
  • mtx_plain — a simple, nonrecursive mutex
  • mtx_timed — a nonrecursive mutex that supports a timeout
  • mtx_plain | mtx_recursive — a recursive mutex
  • mtx_timed | mtx_recursive — a recursive mutex that supports a timeout

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The mtx_init() function initializes the given mutex object. After initialization, the mutex is in an unlocked state.

CAUTION:
You should allocate synchronization objects only in normal memory mappings. On certain processors, atomic operations such as calls to mtx_lock() will cause a fault if the control structure is allocated in uncached memory.
Note: To destroy a mutex, call mtx_destroy(). Once you've destroyed a mutex, don't reuse it without reinitializing it by calling mtx_init().

Returns:

thrd_success
Success.
thrd_error
An error occurred.

Classification:

C11

Safety:  
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes