glibmm 2.56.0

Classes | Public Member Functions | Related Functions | List of all members
Glib::Threads::Mutex Class Reference
Threads

Represents a mutex (mutual exclusion). More...

`#include <glibmm/threads.h>`

## Classes
class | Lock
| Utility class for exception-safe mutex locking. More...

## Public Member Functions
| Mutex ()
| Mutex (const Mutex&)=delete
Mutex& | operator= (const Mutex&)=delete
| ~Mutex ()
void | lock ()
| Locks the mutex. More...
bool | trylock ()
| Tries to lock the mutex. More...
void | unlock ()
| Unlocks the mutex. More...
GMutex* | gobj ()

## Related Functions
(Note that these are not member functions.)
Mutex* | wrap (GMutex* gobject)
| A C++ wrapper for the C object. More...

## Detailed Description

Represents a mutex (mutual exclusion).

It can be used to protect data against shared access. Try to use Mutex::Lock instead of calling lock() and unlock() directly – it will make your life much easier.

Note
  Glib::Threads::Mutex is not recursive, i.e. a thread will deadlock, if it already has locked the mutex while calling lock(). Use Glib::Threads::RecMutex instead, if you need recursive mutexes.

Deprecated:
  Please use std::mutex instead.

## Constructor & Destructor Documentation

## ◆ Mutex() [1/2]

Glib::Threads::Mutex::Mutex | ( |  | ) |

## ◆ Mutex() [2/2]

Glib::Threads::Mutex::Mutex | ( | const Mutex& |  | ) |
| delete

## ◆ ~Mutex()

Glib::Threads::Mutex::~Mutex | ( |  | ) |

## Member Function Documentation

## ◆ gobj()

GMutex* Glib::Threads::Mutex::gobj | ( |  | ) |
| inline

## ◆ lock()

void Glib::Threads::Mutex::lock | ( |  | ) |

Locks the mutex.

If mutex is already locked by another thread, the current thread will block until mutex is unlocked by the other thread.

See also
  Mutex::Lock

## ◆ operator=()

Mutex& Glib::Threads::Mutex::operator= | ( | const Mutex& |  | ) |
| delete

## ◆ trylock()

bool Glib::Threads::Mutex::trylock | ( |  | ) |

Tries to lock the mutex.

If the mutex is already locked by another thread, it immediately returns `false`. Otherwise it locks the mutex and returns `true`.

Returns
  Whether the mutex could be locked.

See also
  Mutex::Lock

## ◆ unlock()

void Glib::Threads::Mutex::unlock | ( |  | ) |

Unlocks the mutex.

If another thread is blocked in a lock() call for this mutex, it will be woken and can lock the mutex itself.

See also
  Mutex::Lock