![]() |
Home | Libraries | People | FAQ | More |
thread
joinable()
join()
try_join_for()
try_join_until()
detach()
get_id()
interrupt()
hardware_concurrency()
physical_concurrency()
native_handle()
swap()
#include <boost/thread/scoped_thread.hpp> template <class CallableThread> class scoped_thread { thread t_; // for exposition purposes only public: scoped_thread() noexcept; scoped_thread(const scoped_thread&) = delete; scoped_thread& operator=(const scoped_thread&) = delete; explicit scoped_thread(thread&& th) noexcept; template <typename F&&, typename ...Args> explicit scoped_thread(F&&, Args&&...); ~scoped_thread(); // move support scoped_thread(scoped_thread && x) noexcept; scoped_thread& operator=(scoped_thread && x) noexcept; void swap(scoped_thread& x) noexcept; typedef thread::id id; id get_id() const noexcept; bool joinable() const noexcept; void join(); #ifdef BOOST_THREAD_USES_CHRONO template <class Rep, class Period> bool try_join_for(const chrono::duration<Rep, Period>& rel_time); template <class Clock, class Duration> bool try_join_until(const chrono::time_point<Clock, Duration>& t); #endif void detach(); static unsigned hardware_concurrency() noexcept; static unsigned physical_concurrency() noexcept; typedef thread::native_handle_type native_handle_type; native_handle_type native_handle(); #if defined BOOST_THREAD_PROVIDES_INTERRUPTIONS void interrupt(); bool interruption_requested() const noexcept; #endif }; void swap(scoped_thread& lhs,scoped_thread& rhs) noexcept;
RAII 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 destructor terminates the program if the thread is joinable. This wrapper can be used to join the thread before destroying it.
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.
boost::scoped_thread<> t((boost::thread(F))); t.interrupt();
scoped_thread() noexcept;
Constructs a scoped_thread instance that wraps to Not-a-Thread.
this->get_id()==thread::id()
Nothing
scoped_thread(scoped_thread&& other) noexcept;
Transfers ownership of the scoped_thread managed by other
(if any) to the newly constructed
scoped_thread instance.
other.get_id()==thread::id()
and get_id()
returns the value of other.get_id()
prior to the construction
Nothing
scoped_thread& operator=(scoped_thread&& other) noexcept;
Transfers ownership of the scoped_thread managed by other
(if any) to *this
.
- if defined BOOST_THREAD_DONT_PROVIDE_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE
:
If there was a scoped_thread
previously associated with *this
then that scoped_thread
is detached, DEPRECATED
- if defined BOOST_THREAD_PROVIDES_THREAD_MOVE_ASSIGN_CALLS_TERMINATE_IF_JOINABLE
:
If the scoped_thread
is joinable calls to std::terminate.
other->get_id()==thread::id()
and get_id()
returns the value of other.get_id()
prior to the assignment.
Nothing
scoped_thread(thread&& t);
Transfers ownership of the thread managed by other
(if any) to the newly constructed scoped_thread instance.
other.get_id()==thread::id() and get_id() returns the value of other.get_id() prior to the construction.
Nothing
template <typename F&&, typename ...Args> explicit scoped_thread(F&&, Args&&...);
Construct an internal thread in place.
*this.t_
refers to the newly created thread of execution and this->get_id()!=thread::id()
.
Any exception the thread construction can throw.
~scoped_thread();
Equivalent to CallableThread()(t_)
.
Nothing: The CallableThread()(t_)
should not throw when joining the
thread as the scoped variable is on a scope outside the thread function.
bool joinable() const noexcept;
Equivalent to return t_.joinable().
Nothing
template <class Rep, class Period> bool try_join_for(const chrono::duration<Rep, Period>& rel_time);
Equivalent to return t_.try_join_for(rel_time)
.
template <class Clock, class Duration> bool try_join_until(const chrono::time_point<Clock, Duration>& abs_time);
Equivalent to return t_.try_join_until(abs_time)
.
thread::id get_id() const noexcept;
Equivalent to return t_.get_id()
.
unsigned hardware_concurrency() noexecpt;
Equivalent to return thread::hardware_concurrency()
.
unsigned physical_concurrency() noexecpt;
Equivalent to return thread::physical_concurrency()
.
typedef thread::native_handle_type native_handle_type; native_handle_type native_handle();
Equivalent to return t_.native_handle()
.
void swap(scoped_thread& other) noexcept;
Equivalent t_.swap(other.t_)
.