Skip to content

named_mutex named_mutex

Alairion edited this page May 8, 2021 · 4 revisions

nes::named_mutex::named_mutex

Functions

(1) explicit named_mutex(const std::string& name);
(2) named_mutex(const named_mutex&) = delete;
(3) named_mutex(named_mutex&&) = delete;
  1. Create a new, or open an existing, named mutex object.
  2. Deleted copy-constructor.
  3. Deleted move-constructor.

Parameters

Name Description
name The UTF-8 encoded name of the named mutex object. The real name of the named mutex object is named_mutex_root + name

Preconditions

name must not be empty.

Complexity

  1. Explicit.
  2. Deleted.
  3. Deleted.

Exceptions

  1. Throws a std::runtime_error if the named mutex object can not be created or opened.
  2. Deleted.
  3. Deleted.

Implementation details

  1. On Windows, first tries to create a new named mutex using CreateMutexW, and if it already exists opens it with OpenMutexW
    On Posix systems, allocates a shared memory object (shm_open + ftruncate) with the specified name (named_mutex_root + name), then construct a process-shared and robust (PTHREAD_PROCESS_SHARED, PTHREAD_MUTEX_ROBUST) mutex inside the shared memory segment, if not already initialized
Clone this wiki locally