Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Namespace this_thread

Non-member function get_id()
Non-member function interruption_point() EXTENSION
Non-member function interruption_requested() EXTENSION
Non-member function interruption_enabled() EXTENSION
Non-member function sleep() DEPRECATED
Non-member function sleep_until()
Non-member function sleep_for()
Non-member function yield()
Class disable_interruption EXTENSION
Constructor
Destructor
Class restore_interruption EXTENSION
Constructor
Destructor
Non-member function template at_thread_exit() EXTENSION
namespace boost {
  namespace this_thread {
    thread::id get_id() noexcept;
    template<typename TimeDuration>
    void yield() noexcept;
    template <class Clock, class Duration>
    void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
    template <class Rep, class Period>
    void sleep_for(const chrono::duration<Rep, Period>& rel_time);

    template<typename Callable>
    void at_thread_exit(Callable func); // EXTENSION

    void interruption_point(); // EXTENSION
    bool interruption_requested() noexcept; // EXTENSION
    bool interruption_enabled() noexcept; // EXTENSION
    class disable_interruption; // EXTENSION
    class restore_interruption; // EXTENSION

  #if defined BOOST_THREAD_USES_DATETIME
    void sleep(TimeDuration const& rel_time); // DEPRECATED
    void sleep(system_time const& abs_time);  // DEPRECATED
  #endif
  }
}
#include <boost/thread/thread.hpp>

namespace this_thread
{
    thread::id get_id() noexcept;
}

Returns:

An instance of boost::thread::id that represents that currently executing thread.

Throws:

boost::thread_resource_error if an error occurs.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    void interruption_point();
}

Effects:

Check to see if the current thread has been interrupted.

Throws:

boost::thread_interrupted if boost::this_thread::interruption_enabled() and boost::this_thread::interruption_requested() both return true.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    bool interruption_requested() noexcept;
}

Returns:

true if interruption has been requested for the current thread, false otherwise.

Throws:

Nothing.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    bool interruption_enabled() noexcept;
}

Returns:

true if interruption has been enabled for the current thread, false otherwise.

Throws:

Nothing.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    template<typename TimeDuration>
    void sleep(TimeDuration const& rel_time);
    void sleep(system_time const& abs_time)
}
[Warning] Warning

DEPRECATED since 3.0.0.

Use sleep_for() and sleep_until() instead.

Effects:

Suspends the current thread until the time period specified by rel_time has elapsed or the time point specified by abs_time has been reached.

Throws:

boost::thread_interrupted if the current thread of execution is interrupted.

Notes:

sleep() is one of the predefined interruption points.

#include <boost/thread/thread.hpp>

namespace this_thread
{
  template <class Clock, class Duration>
  void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
  namespace no_interruption_point
  {
    template <class Clock, class Duration>
    void sleep_until(const chrono::time_point<Clock, Duration>& abs_time);
  }
}

Effects:

Suspends the current thread until the time point specified by abs_time has been reached.

Throws:

Nothing if Clock satisfies the TrivialClock requirements and operations of Duration do not throw exceptions. boost::thread_interrupted if the current thread of execution is interrupted.

Notes:

sleep_until() is one of the predefined interruption points.

Notes:

no_interruption_point::sleep_until() is NOT one of the interruption points.

#include <boost/thread/thread.hpp>

namespace this_thread
{
  template <class Rep, class Period>
  void sleep_for(const chrono::duration<Rep, Period>& rel_time);
  namespace no_interruption_point
  {
    template <class Rep, class Period>
    void sleep_for(const chrono::duration<Rep, Period>& rel_time);
  }
}

Effects:

Suspends the current thread until the duration specified by rel_time has elapsed.

Throws:

Nothing if operations of chrono::duration<Rep, Period> do not throw exceptions. boost::thread_interrupted if the current thread of execution is interrupted.

Notes:

sleep_for() is one of the predefined interruption points.

Notes:

no_interruption_point:: sleep_for() is NOT one of the interruption points.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    void yield() noexcept;
}

Effects:

Gives up the remainder of the current thread's time slice, to allow other threads to run.

Throws:

Nothing.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    class disable_interruption
    {
    public:
        disable_interruption(const disable_interruption&) = delete;
        disable_interruption& operator=(const disable_interruption&) = delete;
        disable_interruption() noexcept;
        ~disable_interruption() noexcept;
    };
}

boost::this_thread::disable_interruption disables interruption for the current thread on construction, and restores the prior interruption state on destruction. Instances of disable_interruption cannot be copied or moved.

disable_interruption() noexcept;

Effects:

Stores the current state of boost::this_thread::interruption_enabled() and disables interruption for the current thread.

Postconditions:

boost::this_thread::interruption_enabled() returns false for the current thread.

Throws:

Nothing.

~disable_interruption() noexcept;

Preconditions:

Must be called from the same thread from which *this was constructed.

Effects:

Restores the current state of boost::this_thread::interruption_enabled() for the current thread to that prior to the construction of *this.

Postconditions:

boost::this_thread::interruption_enabled() for the current thread returns the value stored in the constructor of *this.

Throws:

Nothing.

#include <boost/thread/thread.hpp>

namespace this_thread
{
    class restore_interruption
    {
    public:
        restore_interruption(const restore_interruption&) = delete;
        restore_interruption& operator=(const restore_interruption&) = delete;
        explicit restore_interruption(disable_interruption& disabler) noexcept;
        ~restore_interruption() noexcept;
    };
}

On construction of an instance of boost::this_thread::restore_interruption, the interruption state for the current thread is restored to the interruption state stored by the constructor of the supplied instance of boost::this_thread::disable_interruption. When the instance is destroyed, interruption is again disabled. Instances of restore_interruption cannot be copied or moved.

explicit restore_interruption(disable_interruption& disabler) noexcept;

Preconditions:

Must be called from the same thread from which disabler was constructed.

Effects:

Restores the current state of boost::this_thread::interruption_enabled() for the current thread to that prior to the construction of disabler.

Postconditions:

boost::this_thread::interruption_enabled() for the current thread returns the value stored in the constructor of disabler.

Throws:

Nothing.

~restore_interruption() noexcept;

Preconditions:

Must be called from the same thread from which *this was constructed.

Effects:

Disables interruption for the current thread.

Postconditions:

boost::this_thread::interruption_enabled() for the current thread returns false.

Throws:

Nothing.

#include <boost/thread/thread.hpp>

template<typename Callable>
void at_thread_exit(Callable func);

Effects:

A copy of func is placed in thread-specific storage. This copy is invoked when the current thread exits (even if the thread has been interrupted).

Postconditions:

A copy of func has been saved for invocation on thread exit.

Throws:

std::bad_alloc if memory cannot be allocated for the copy of the function, boost::thread_resource_error if any other error occurs within the thread library. Any exception thrown whilst copying func into internal storage.

Note:

This function is not called if the thread was terminated forcefully using platform-specific APIs, or if the thread is terminated due to a call to exit(), abort() or std::terminate(). In particular, returning from main() is equivalent to call to exit(), so will not call any functions registered with at_thread_exit()


PrevUpHomeNext