Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class strict_scoped_thread

Constructor from a thread
Move Constructor from a Callable
Destructor
// #include <boost/thread/scoped_thread.hpp>

template <class CallableThread = join_if_joinable>
class strict_scoped_thread
{
  thread t_; // for exposition purposes only
public:

  strict_scoped_thread(strict_scoped_thread const&) = delete;
  strict_scoped_thread& operator=(strict_scoped_thread const&) = delete;

  explicit strict_scoped_thread(thread&& t) noexcept;
  template <typename F&&, typename ...Args>
  explicit strict_scoped_thread(F&&, Args&&...);

  ~strict_scoped_thread();

};

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 a 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.

Example
boost::strict_scoped_thread<> t((boost::thread(F)));
explicit strict_scoped_thread(thread&& t) noexcept;

Effects:

move the thread to own t_

Throws:

Nothing

template <typename F&&, typename ...Args>
explicit strict_scoped_thread(F&&, Args&&...);

Effects:

Construct an internal thread in place.

Postconditions:

*this.t_ refers to the newly created thread of execution and this->get_id()!=thread::id().

Throws:

Any exception the thread construction can throw.

~strict_scoped_thread();

Effects:

Equivalent to CallableThread()(t_).

Throws:

Nothing: The CallableThread()(t_) should not throw when joining the thread as the scoped variable is on a scope outside the thread function.


PrevUpHomeNext