Library Version 18.1.40

DbEnv::mutex_alloc()
Prev | Chapter 10. Mutex Methods | Next

## DbEnv::mutex_alloc()

    #include <db_cxx.h>

    int
    DbEnv::mutex_alloc(u_int32_t flags, db_mutex_t *mutexp);

The `DbEnv::mutex_alloc()` method allocates a mutex and returns a reference to it into the memory specified by mutexp.

The `DbEnv::mutex_alloc()` method may not be called before the DbEnv::open() method is called.

The `DbEnv::mutex_alloc()` method either returns a non-zero error value or throws an exception that encapsulates a non-zero error value on failure, and returns 0 on success.

### Parameters

#### flags

The flags parameter must be set to 0 or by bitwise inclusively OR'ing together one or more of the following values:

- `DB_MUTEX_PROCESS_ONLY`

  The mutex is associated with a single process. The DbEnv::failchk() method will release mutexes held by any process which has exited.

- `DB_MUTEX_SELF_BLOCK`

  The mutex must be self-blocking. That is, if a thread of control locks the mutex and then attempts to lock the mutex again, the thread of control will block until another thread of control releases the original lock on the mutex, allowing the original thread of control to lock the mutex the second time. Attempting to re-acquire a mutex for which the `DB_MUTEX_SELF_BLOCK` flag was not specified will result in undefined behavior.

#### mutexp

The mutexp parameter references memory into which the mutex reference is copied.

### Errors

The `DbEnv::mutex_alloc()` method may fail and throw a DbException exception, encapsulating one of the following non-zero errors, or return one of the following non-zero errors:

#### EINVAL

An invalid flag value or parameter was specified.

### Class

DbEnv

### See Also

Mutex Methods

Prev | Up | Next
Chapter 10. Mutex Methods | Home | DbEnv::mutex_free()