libfoedus-core
FOEDUS Core Library
foedus::thread::Rendezvous Class Referencefinal

The frequently appearing triplet of condition_varible, "signal" flag for spurious wakeup, and mutex for a one-time single-producer multiple-consumer event synchronization. More...

Detailed Description

The frequently appearing triplet of condition_varible, "signal" flag for spurious wakeup, and mutex for a one-time single-producer multiple-consumer event synchronization.

This is basically equivalent to std::promise/future pair with no parameter. The frequent use case is to synchronize with some event for one producer and many waiters. We did use std::promise/future pair for this purpose, but we encountered a bug in libstdc's implementation of std::promise/future. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57440

We are not sure when the fix will be made, nor when the fixed version of gcc/libstdc++ will be prevalent to all environments we support. Very unlikely we can't afford to wait for it. Therefore, we roll it our own.

As this depends on C++11, the name of this file ends with impl. Thus, only private implementation classes directly use this class. If you are okay with C++11, you can use it from client programs, too.

This class is totally header-only.

Definition at line 49 of file rendezvous_impl.hpp.

#include <rendezvous_impl.hpp>

Public Member Functions

 Rendezvous ()
 
 Rendezvous (const Rendezvous &other)=delete
 
Rendezvousoperator= (const Rendezvous &other)=delete
 
 Rendezvous (Rendezvous &&other)=delete
 
Rendezvousoperator= (Rendezvous &&other)=delete
 
void wait ()
 Block until the event happens. More...
 
template<class REP , class PERIOD >
bool wait_for (const std::chrono::duration< REP, PERIOD > &timeout)
 Block until the event happens or the given period elapses. More...
 
template<class CLOCK , class DURATION >
bool wait_until (const std::chrono::time_point< CLOCK, DURATION > &until)
 Block until the event happens or the given time point arrives. More...
 
void signal ()
 Notify all waiters that the event has happened. More...
 
bool is_signaled () const
 returns whether this thread has stopped (if the thread hasn't started, false too). More...
 
bool is_signaled_weak () const
 non-atomic is_signaled(). More...
 

Constructor & Destructor Documentation

foedus::thread::Rendezvous::Rendezvous ( )
inline

Definition at line 51 of file rendezvous_impl.hpp.

51 : signaled_(false) {}
foedus::thread::Rendezvous::Rendezvous ( const Rendezvous other)
delete
foedus::thread::Rendezvous::Rendezvous ( Rendezvous &&  other)
delete

Member Function Documentation

bool foedus::thread::Rendezvous::is_signaled ( ) const
inline

returns whether this thread has stopped (if the thread hasn't started, false too).

Definition at line 115 of file rendezvous_impl.hpp.

Referenced by signal(), wait(), wait_for(), and wait_until().

115  {
116  return signaled_.load();
117  }

Here is the caller graph for this function:

bool foedus::thread::Rendezvous::is_signaled_weak ( ) const
inline

non-atomic is_signaled().

Definition at line 119 of file rendezvous_impl.hpp.

119  {
120  return signaled_.load(std::memory_order_relaxed);
121  }
Rendezvous& foedus::thread::Rendezvous::operator= ( const Rendezvous other)
delete
Rendezvous& foedus::thread::Rendezvous::operator= ( Rendezvous &&  other)
delete
void foedus::thread::Rendezvous::signal ( )
inline

Notify all waiters that the event has happened.

Equivalent to std::promise<void>::set_value(). There must be only one thread that might call this method, and it should call this only once. Otherwise, the behavior is undefined.

Definition at line 106 of file rendezvous_impl.hpp.

References ASSERT_ND, is_signaled(), and foedus::thread::ConditionVariable::notify_all().

106  {
108  condition_.notify_all([this]{ signaled_.store(true); });
109  // we must not put ANYTHING after this because notified waiters might have already
110  // deleted this object. notify_broadcast() guarantees that itself finishes before
111  // destruction, but no guarantee after that.
112  }
void notify_all(SIGNAL_ACTION signal_action)
Notify all waiters that the event has happened.
bool is_signaled() const
returns whether this thread has stopped (if the thread hasn't started, false too).
#define ASSERT_ND(x)
A warning-free wrapper macro of assert() that has no performance effect in release mode even when 'x'...
Definition: assert_nd.hpp:72

Here is the call graph for this function:

void foedus::thread::Rendezvous::wait ( )
inline

Block until the event happens.

Equivalent to std::future<void>::wait().

Definition at line 64 of file rendezvous_impl.hpp.

References is_signaled(), and foedus::thread::ConditionVariable::wait().

64  {
65  if (is_signaled()) {
66  return;
67  }
68  condition_.wait([this]{ return is_signaled(); });
69  }
bool is_signaled() const
returns whether this thread has stopped (if the thread hasn't started, false too).
void wait(PREDICATE predicate)
Block until the event happens.

Here is the call graph for this function:

template<class REP , class PERIOD >
bool foedus::thread::Rendezvous::wait_for ( const std::chrono::duration< REP, PERIOD > &  timeout)
inline

Block until the event happens or the given period elapses.

Returns
whether the event happened by now.

Equivalent to std::future<void>::wait_for().

Definition at line 78 of file rendezvous_impl.hpp.

References is_signaled(), and foedus::thread::ConditionVariable::wait_for().

78  {
79  if (is_signaled()) {
80  return true;
81  }
82  return condition_.wait_for(timeout, [this]{ return is_signaled(); });
83  }
bool is_signaled() const
returns whether this thread has stopped (if the thread hasn't started, false too).
bool wait_for(const std::chrono::duration< REP, PERIOD > &timeout, PREDICATE predicate)
Block until the event happens or the given period elapses.

Here is the call graph for this function:

template<class CLOCK , class DURATION >
bool foedus::thread::Rendezvous::wait_until ( const std::chrono::time_point< CLOCK, DURATION > &  until)
inline

Block until the event happens or the given time point arrives.

Returns
whether the event happened by now.

Equivalent to std::future<void>::wait_until().

Definition at line 92 of file rendezvous_impl.hpp.

References is_signaled(), and foedus::thread::ConditionVariable::wait_until().

92  {
93  if (is_signaled()) {
94  return true;
95  }
96  return condition_.wait_until(until, [this]{ return is_signaled(); });
97  }
bool is_signaled() const
returns whether this thread has stopped (if the thread hasn't started, false too).
bool wait_until(const std::chrono::time_point< CLOCK, DURATION > &until, PREDICATE predicate)
Block until the event happens or the given time point arrives.

Here is the call graph for this function:


The documentation for this class was generated from the following file: