Boost  v1.57.0
doxygen for www.boost.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
boost::scoped_thread< CallableThread > Class Template Reference

RAI thread wrapper adding a specific destroyer allowing to master what can be done at destruction time. More...

#include <scoped_thread.hpp>

Public Types

typedef thread::id id
 

Public Member Functions

 BOOST_THREAD_MOVABLE_ONLY (scoped_thread) scoped_thread() BOOST_NOEXCEPT
 Movable only. More...
 
template<class F , class... Args, typename = typename disable_if<is_same<typename decay<F>::type, thread>, void* >::type>
 scoped_thread (BOOST_THREAD_FWD_REF(F) f, BOOST_THREAD_FWD_REF(Args)...args)
 
 scoped_thread (BOOST_THREAD_RV_REF(thread) t) BOOST_NOEXCEPT
 Constructor from the thread to own. More...
 
 scoped_thread (BOOST_RV_REF(scoped_thread) x) BOOST_NOEXCEPT
 Move constructor. More...
 
 ~scoped_thread ()
 Destructor. More...
 
scoped_threadoperator= (BOOST_RV_REF(scoped_thread) x)
 Move assignment. More...
 
void swap (scoped_thread &x) BOOST_NOEXCEPT
 
thread::id get_id () const BOOST_NOEXCEPT
 
void detach ()
 
void join ()
 
thread::native_handle_type native_handle () BOOST_NOEXCEPT
 
bool joinable () const BOOST_NOEXCEPT
 

Static Public Member Functions

static unsigned hardware_concurrency () BOOST_NOEXCEPT
 

Detailed Description

template<class CallableThread = join_if_joinable>
class boost::scoped_thread< CallableThread >

RAI thread wrapper adding a specific destroyer allowing to master what can be done at destruction time.

CallableThread: A callable void(thread&) . The default is join_if_joinable.

thread std::thread destructor terminates the program if the thread is not joinable. Having a wrapper that can join the thread before destroying it seems a natural need.

Remark: scoped_thread is not a thread as thread is not designed to be derived from as a polymorphic type. Anyway scoped_thread can be used in most of the contexts a thread could be used as it has the same non-deprecated interface with the exception of the construction.

Example:

boost::scoped_thread<> t((boost::thread(F)));
t.interrupt();

Member Typedef Documentation

template<class CallableThread = join_if_joinable>
typedef thread::id boost::scoped_thread< CallableThread >::id

Constructor & Destructor Documentation

template<class CallableThread = join_if_joinable>
template<class F , class... Args, typename = typename disable_if<is_same<typename decay<F>::type, thread>, void* >::type>
boost::scoped_thread< CallableThread >::scoped_thread ( BOOST_THREAD_FWD_REF(F)  f,
BOOST_THREAD_FWD_REF(Args)...  args 
)
inlineexplicit
template<class CallableThread = join_if_joinable>
boost::scoped_thread< CallableThread >::scoped_thread ( BOOST_THREAD_RV_REF(thread)  t)
inlineexplicit

Constructor from the thread to own.

Parameters
tthe thread to own.

Effects: move the thread to own t.

template<class CallableThread = join_if_joinable>
boost::scoped_thread< CallableThread >::scoped_thread ( BOOST_RV_REF(scoped_thread< CallableThread >)  x)
inline

Move constructor.

template<class CallableThread = join_if_joinable>
boost::scoped_thread< CallableThread >::~scoped_thread ( )
inline

Destructor.

Effects: Call the CallableThread functor before destroying the owned thread.

Member Function Documentation

template<class CallableThread = join_if_joinable>
boost::scoped_thread< CallableThread >::BOOST_THREAD_MOVABLE_ONLY ( scoped_thread< CallableThread >  )
inline

Movable only.

Default Constructor.

Effects: wraps a not-a-thread.

template<class CallableThread = join_if_joinable>
void boost::scoped_thread< CallableThread >::detach ( )
inline
template<class CallableThread = join_if_joinable>
thread::id boost::scoped_thread< CallableThread >::get_id ( ) const
inline
template<class CallableThread = join_if_joinable>
static unsigned boost::scoped_thread< CallableThread >::hardware_concurrency ( )
inlinestatic
template<class CallableThread = join_if_joinable>
void boost::scoped_thread< CallableThread >::join ( )
inline
template<class CallableThread = join_if_joinable>
bool boost::scoped_thread< CallableThread >::joinable ( ) const
inline
template<class CallableThread = join_if_joinable>
thread::native_handle_type boost::scoped_thread< CallableThread >::native_handle ( )
inline
template<class CallableThread = join_if_joinable>
scoped_thread& boost::scoped_thread< CallableThread >::operator= ( BOOST_RV_REF(scoped_thread< CallableThread >)  x)
inline

Move assignment.

References boost::move().

template<class CallableThread = join_if_joinable>
void boost::scoped_thread< CallableThread >::swap ( scoped_thread< CallableThread > &  x)
inline

References boost::flyweights::x.


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