An opaque data structure to represent a condition.
More...
#include <glibmm/thread.h>
An opaque data structure to represent a condition.
A Cond is an object that threads can block on, if they find a certain condition to be false. If other threads change the state of this condition they can signal the Cond, such that the waiting thread is woken up.
- Usage example:
void* current_data = nullptr;
void push_data(void* data)
{
}
void* pop_data()
{
while (!current_data)
data_cond.
wait(data_mutex);
void *
const data = current_data;
current_data = nullptr;
}
void lock(_L1 &__l1, _L2 &__l2, _L3 &... __l3)
constexpr auto data(_Container &__cont) noexcept(noexcept(__cont.data())) -> decltype(__cont.data())
An opaque data structure to represent a condition.
Definition: thread.h:719
void signal()
If threads are waiting for this Cond, exactly one of them is woken up.
void wait(Mutex &mutex)
Waits until this thread is woken up on this Cond.
Utility class for exception-safe mutex locking.
Definition: thread.h:486
Represents a mutex (mutual exclusion).
Definition: thread.h:431
- Deprecated:
- Use Glib::Threads::Cond instead.
◆ Cond() [1/2]
◆ Cond() [2/2]
Glib::Cond::Cond |
( |
const Cond & |
| ) |
|
|
delete |
◆ ~Cond()
◆ broadcast()
void Glib::Cond::broadcast |
( |
| ) |
|
If threads are waiting for this Cond, all of them are woken up.
It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.
◆ gobj()
GCond * Glib::Cond::gobj |
( |
| ) |
|
|
inline |
◆ operator=()
Cond & Glib::Cond::operator= |
( |
const Cond & |
| ) |
|
|
delete |
◆ signal()
void Glib::Cond::signal |
( |
| ) |
|
If threads are waiting for this Cond, exactly one of them is woken up.
It is good practice to hold the same lock as the waiting thread, while calling this method, though not required.
◆ timed_wait()
Waits until this thread is woken up on this Cond, but not longer than until the time, that is specified by abs_time.
The mutex is unlocked before falling asleep and locked again before resuming.
- Parameters
-
mutex | a Mutex that is currently locked. |
abs_time | a max time to wait. |
- Note
- It is important to use the wait() and timed_wait() methods only inside a loop, which checks for the condition to be true as it is not guaranteed that the waiting thread will find it fulfilled, even if the signaling thread left the condition in that state. This is because another thread can have altered the condition, before the waiting thread got the chance to be woken up, even if the condition itself is protected by a Mutex.
◆ wait()
void Glib::Cond::wait |
( |
Mutex & |
mutex | ) |
|
Waits until this thread is woken up on this Cond.
The mutex is unlocked before falling asleep and locked again before resuming.
- Parameters
-
mutex | a Mutex that is currently locked. |
- Note
- It is important to use the wait() and timed_wait() methods only inside a loop, which checks for the condition to be true as it is not guaranteed that the waiting thread will find it fulfilled, even if the signaling thread left the condition in that state. This is because another thread can have altered the condition, before the waiting thread got the chance to be woken up, even if the condition itself is protected by a Mutex.