MADNESS 0.10.1
madness::Future< Future< T > > Class Template Reference

A future of a future is forbidden (by deleted constructor). More...

#include <future.h>

Public Types

typedef RemoteReference< FutureImpl< T > > remote_refT

Public Member Functions

 ~Future ()
 Destructor.
T & get (bool dowork=true) &
 Gets the value, waiting if necessary.
bool is_default_initialized () const
 Check if the future is default initialized.
bool is_local () const
 Checks the future remoteness trait.
bool is_remote () const
 Checks the future remoteness trait.
 operator const T & () const &
 Same as get() const&.
 operator T () &&
 An rvalue analog of get().
 operator T& () &
 Same as get()&.
Future< T > & operator= (const Future< T > &other)
 Shallow assignment operator.
bool probe () const
 Check whether this future has been assigned.
void register_callback (CallbackInterface *callback)
 Registers an object to be called when future is assigned.
remote_refT remote_ref (World &world) const
 Returns a structure used to pass references to another process.
void set (const Future< T > &other)
 A.set(B), where A and B are futures ensures A has/will have the same value as B.

Static Public Member Functions

static const Future< T > default_initializer ()
 See "Gotchas" on Futures about why this exists and how to use it.

Private Member Functions

 Future ()=delete

Private Attributes

char buffer [sizeof(T)]
 Buffer to hold a single T object.
atomic_shared_ptr< FutureImpl< T > > f
 Pointer to the implementation object.
T *const value
 Pointer to buffer when it holds a T object.

Friends

std::ostream & operator<< (std::ostream &out, const Future< T > &f)
 Human readable printing of a Future to a stream.

Detailed Description

template<typename T>
class madness::Future< Future< T > >

A future of a future is forbidden (by deleted constructor).

Template Parameters
TThe type of future.

Member Typedef Documentation

◆ remote_refT

typedef RemoteReference< FutureImpl<T> > madness::Future< T >::remote_refT
Todo
Brief description needed.

Constructor & Destructor Documentation

◆ Future()

template<typename T>
madness::Future< Future< T > >::Future ( )
privatedelete

◆ ~Future()

madness::Future< T >::~Future ( )
inline

Destructor.

Member Function Documentation

◆ default_initializer()

const Future< T > madness::Future< T >::default_initializer ( )
inlinestatic

See "Gotchas" on Futures about why this exists and how to use it.

Todo
Informative description needed.

◆ get()

T & madness::Future< T >::get ( bool dowork = true) &
inline

Gets the value, waiting if necessary.

Parameters
doworkIf true (default) and the future is not ready this thread will execute other tasks while waiting
Warning
PaRSEC backend does not support dowork=true from a callstack containing a running MADNESS task already, hence must use dowork=false when need to call from within a task
Returns
reference to the contained value
Precondition
this->is_local()

◆ is_default_initialized()

bool madness::Future< T >::is_default_initialized ( ) const
inline

Check if the future is default initialized.

Returns
True if this future was constructed with default_initializer(); false otherwise.

◆ is_local()

bool madness::Future< T >::is_local ( ) const
inline

Checks the future remoteness trait.

Returns
true if the future refers to an already available or to-be-locally-produced result

◆ is_remote()

bool madness::Future< T >::is_remote ( ) const
inline

Checks the future remoteness trait.

Returns
true if the future refers to another future on a another rank, i.e. it will be set when the referred-to future is set

◆ operator const T &()

madness::Future< T >::operator const T & ( ) const &
inline

Same as get() const&.

Returns
A const lvalue reference to the value.

◆ operator T()

madness::Future< T >::operator T ( ) &&
inline

An rvalue analog of get().

Returns
An rvalue reference to the value.

◆ operator T&()

madness::Future< T >::operator T& ( ) &
inline

Same as get()&.

Returns
An lvalue reference to the value.

◆ operator=()

Future< T > & madness::Future< T >::operator= ( const Future< T > & other)
inline

Shallow assignment operator.

Parameters
[in]otherThe future to copy.
Returns
This.

◆ probe()

bool madness::Future< T >::probe ( ) const
inline

Check whether this future has been assigned.

Returns
True if the future has been assigned; false otherwise.

◆ register_callback()

void madness::Future< T >::register_callback ( CallbackInterface * callback)
inline

Registers an object to be called when future is assigned.

Callbacks are invoked in the order registered. If the future is already assigned, the callback is immediately invoked.

Parameters
[in]callbackThe callback to be invoked.

◆ remote_ref()

remote_refT madness::Future< T >::remote_ref ( World & world) const
inline

Returns a structure used to pass references to another process.

This is used for passing pointers/references to another process. To make remote references completely safe, the RemoteReference increments the internal reference count of the Future. The counter is decremented by either assigning to the remote Future or its destructor if it is never assigned. The remote Future is only useful for setting the future. It will not be notified if the value is set elsewhere.

If this is already a reference to a remote future, the actual remote reference is returned; that is, not a a reference to the local future. Therefore, the local future will not be notified when the result is set (i.e., the communication is short circuited).

Parameters
[in,out]worldThe communication world.
Todo
Verify the return comment.
Returns
The remote reference.

◆ set()

void madness::Future< T >::set ( const Future< T > & other)
inline

A.set(B), where A and B are futures ensures A has/will have the same value as B.

An exception is thrown if A is already assigned since a Future is a single assignment variable. We don't yet track multiple assignments from unassigned futures.

If B is already assigned, this is the same as A.set(B.get()), which sets A to the value of B.

If B has not yet been assigned, the behavior is to ensure that, when B is assigned, both A and B will be assigned and have the same value (though they may/may not refer to the same underlying copy of the data and indeed may even be in different processes).

Todo
Verification needed in the param statement.
Parameters
[in]otherThe future B described above. *this is A.

◆ operator<<

std::ostream & operator<< ( std::ostream & out,
const Future< T > & f )
friend

Human readable printing of a Future to a stream.

Stream output operator for a future.

Template Parameters
TThe type of future.
Parameters
[in,out]outThe output stream.
[in]fThe future.
Returns
The output stream.
Todo
Brief description needed.
Todo
Descriptions needed.
Template Parameters
TDescription needed.
Parameters
[in,out]Theoutput stream.
[in]fThe future to be output.
Returns
The output stream.

Member Data Documentation

◆ buffer

char madness::Future< T >::buffer[sizeof(T)]
private

Buffer to hold a single T object.

◆ f

Pointer to the implementation object.

◆ value

T* const madness::Future< T >::value
private

Pointer to buffer when it holds a T object.


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