...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
In general, this_fiber
operations
may be called from the “main” fiber — the fiber on which function
main()
is entered — as well as from an explicitly-launched thread’s thread-function.
That is, in many respects the main fiber on each thread can be treated like
an explicitly-launched fiber.
namespace boost { namespace this_fiber { fibers::fiber::id get_id() noexcept; void yield() noexcept; template< typename Clock, typename Duration > void sleep_until( std::chrono::time_point< Clock, Duration > const&); template< typename Rep, typename Period > void sleep_for( std::chrono::duration< Rep, Period > const&); template< typename PROPS > PROPS & properties(); }}
this_fiber::get_id()
#include <boost/fiber/operations.hpp> namespace boost { namespace fibers { fiber::id get_id() noexcept; }}
An instance of fiber::id
that
represents the currently executing fiber.
Nothing.
this_fiber::sleep_until()
#include <boost/fiber/operations.hpp> namespace boost { namespace fibers { template< typename Clock, typename Duration > void sleep_until( std::chrono::time_point< Clock, Duration > const& abs_time); }}
Suspends the current fiber until the time point specified by abs_time
has been reached.
timeout-related exceptions.
The current fiber will not resume before abs_time
,
but there are no guarantees about how soon after abs_time
it might resume.
“timeout-related exceptions” are as defined in the C++ Standard, section 30.2.4 Timing specifications [thread.req.timing]: “A function that takes an argument which specifies a timeout will throw if, during its execution, a clock, time point, or time duration throws an exception. Such exceptions are referred to as timeout-related exceptions.”
this_fiber::sleep_for()
#include <boost/fiber/operations.hpp> namespace boost { namespace fibers { template< class Rep, class Period > void sleep_for( std::chrono::duration< Rep, Period > const& rel_time); }}
Suspends the current fiber until the time duration specified by rel_time
has elapsed.
timeout-related exceptions.
The current fiber will not resume before rel_time
has elapsed, but there are no guarantees about how soon after that
it might resume.
this_fiber::yield()
#include <boost/fiber/operations.hpp> namespace boost { namespace fibers { void yield() noexcept; }}
Relinquishes execution control, allowing other fibers to run.
Nothing.
A fiber that calls yield()
is not suspended: it is immediately
passed to the scheduler as ready to run.
this_fiber::properties()
#include <boost/fiber/operations.hpp> namespace boost { namespace fibers { template< typename PROPS > PROPS & properties(); }}
use_scheduling_algorithm()
has been called from
this thread with a subclass of algorithm_with_properties<>
with
the same template argument PROPS
.
a reference to the scheduler properties instance for the currently running fiber.
std::bad_cast
if use_scheduling_algorithm()
was called with an algorithm_with_properties
subclass
with some other template parameter than PROPS
.
algorithm_with_properties<>
provides
a way for a user-coded scheduler to associate extended properties,
such as priority, with a fiber instance. This function allows access
to those user-provided properties.
The first time this function is called from the main fiber of a thread, it may internally yield, permitting other fibers to run.