From 5d18cd5a4e5e9d9e5a39e0dcc7e51603199f292c Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 21 Jun 2015 10:53:37 +0200 Subject: [PATCH] add interruption point after fiber_manager::run() - functions fiber_manager::join()/fiber_manager::yield()/fiber_manager:.wait()/fiber_manager_wait_until() check for interrption of the current fiber --- doc/fiber.qbk | 3 + doc/fibers.qbk | 2 + doc/fibers.xml | 625 +++++++++++++++--------------- doc/html/fiber/fiber_mgmt.html | 11 + doc/html/fiber/performance.html | 616 ++++++++++++++--------------- doc/html/index.html | 2 +- include/boost/fiber/condition.hpp | 7 - src/fiber_manager.cpp | 15 +- 8 files changed, 660 insertions(+), 621 deletions(-) diff --git a/doc/fiber.qbk b/doc/fiber.qbk index 4118f801..1100bd03 100644 --- a/doc/fiber.qbk +++ b/doc/fiber.qbk @@ -176,8 +176,11 @@ __interruption_enabled__. * __cond_wait__ * __cond_wait_for__ * __cond_wait_until__ +* __mutex_lock__ (__recursive_mutex__, __recursive_timed_mutex__, __timed_mutex__) +* __mutex_try_lock__ (__recursive_mutex__, __recursive_timed_mutex__, __timed_mutex__) * __sleep_for__ * __sleep_until__ +* __yield__ * __interruption_point__ [#class_fiber_id] diff --git a/doc/fibers.qbk b/doc/fibers.qbk index b78d9e0b..f7f98b70 100644 --- a/doc/fibers.qbk +++ b/doc/fibers.qbk @@ -139,6 +139,8 @@ [def __interrupt__ [member_link fiber..interrupt]] [def __io_service__ `boost::asio::io_service`] [def __join__ [member_link fiber..join]] +[def __mutex_lock__ [member_link mutex..lock]] +[def __mutex_try_lock__ [member_link mutex..try_lock]] [def __run_service__ `boost::fibers::asio::run_service()`] [def __shared_future_get__ [member_link shared_future..get]] [def __sleep_for__ [ns_function_link this_fiber..sleep_for]] diff --git a/doc/fibers.xml b/doc/fibers.xml index 7d3d9641..42e8bffe 100644 --- a/doc/fibers.xml +++ b/doc/fibers.xml @@ -1,6 +1,6 @@ - @@ -355,6 +355,18 @@ method. condition_variable::wait_until() + + + mutex::lock() ( recursive_mutex, recursive_timed_mutex, + timed_mutex) + + + + + mutex::try_lock() ( recursive_mutex, + recursive_timed_mutex, timed_mutex) + + this_fiber::sleep_for() @@ -365,6 +377,11 @@ method. this_fiber::sleep_until() + + + this_fiber::yield() + + this_fiber::interruption_point() @@ -7005,7 +7022,7 @@ are - 955 ns + 1.1 µs @@ -7081,7 +7098,7 @@ are - 1.1 µs + 1.3 µs @@ -7089,306 +7106,6 @@ are - Overhead of waiting on a future - - - - - - thread - - - - - fiber - - - - - - - - - 32 µs - - - - - 2.4 µs - - - - - -
- - Scaling of creating and joining - - - - - - average of - - - - - thread - - - - - fiber - - - - - - - - - 10 - - - - - 50.65 µs - - - - - 3.76 µs - - - - - - - 50 - - - - - 52.99 µs - - - - - 2.78 µs - - - - - - - 100 - - - - - 50.44 µs - - - - - 2.45 µs - - - - - - - 500 - - - - - 45.19 µs - - - - - 2.91 µs - - - - - - - 1000 - - - - - 42.59 µs - - - - - 3.60 µs - - - - - - - 5000 - - - - - 42.30 µs - - - - - 4.57 µs - - - - - - - 10000 - - - - - 41.07 µs - - - - - 4.21 µs - - - - - -
- - Using internally atomics by applying BOOST_FIBER_USE_ATOMICS. - - - Overhead of creating and joining - - - - - - thread - - - - - fiber - - - - - tbb - - - - - qthread - - - - - - - - - 31 µs - - - - - 1.1 µs - - - - - 570 ns - - - - - 620 ns - - - - - -
- - Overhead of detach - - - - - - thread - - - - - fiber - - - - - - - - - 20 µs - - - - - 3.2 µs - - - - - -
- - Overhead of yield - - - - - - thread - - - - - fiber - - - - - - - - - 38 µs - - - - - 1.3 µs - - - - - -
- Overhead of waiting on a future @@ -7421,7 +7138,7 @@ are
- +
Scaling of creating and joining @@ -7566,6 +7283,306 @@ are
+ + Using internally atomics by applying BOOST_FIBER_NO_ATOMICS. + + + Overhead of creating and joining + + + + + + thread + + + + + fiber + + + + + tbb + + + + + qthread + + + + + + + + + 31 µs + + + + + 955 ns + + + + + 570 ns + + + + + 620 ns + + + + + +
+ + Overhead of detach + + + + + + thread + + + + + fiber + + + + + + + + + 20 µs + + + + + 3.2 µs + + + + + +
+ + Overhead of yield + + + + + + thread + + + + + fiber + + + + + + + + + 38 µs + + + + + 1.1 µs + + + + + +
+ + Overhead of waiting on a future + + + + + + thread + + + + + fiber + + + + + + + + + 32 µs + + + + + 2.4 µs + + + + + +
+ + Scaling of creating and joining + + + + + + average of + + + + + thread + + + + + fiber + + + + + + + + + 10 + + + + + 50.65 µs + + + + + 3.76 µs + + + + + + + 50 + + + + + 52.99 µs + + + + + 2.78 µs + + + + + + + 100 + + + + + 50.44 µs + + + + + 2.45 µs + + + + + + + 500 + + + + + 45.19 µs + + + + + 2.91 µs + + + + + + + 1000 + + + + + 42.59 µs + + + + + 3.60 µs + + + + + + + 5000 + + + + + 42.30 µs + + + + + 4.57 µs + + + + + + + 10000 + + + + + 41.07 µs + + + + + 4.21 µs + + + + + +
<link linkend="fiber.rational">Rational</link> diff --git a/doc/html/fiber/fiber_mgmt.html b/doc/html/fiber/fiber_mgmt.html index 850356a9..bac40ebb 100644 --- a/doc/html/fiber/fiber_mgmt.html +++ b/doc/html/fiber/fiber_mgmt.html @@ -236,12 +236,23 @@ method.
  • condition_variable::wait_until()
  • +
  • + mutex::lock() ( recursive_mutex, recursive_timed_mutex, + timed_mutex) +
  • +
  • + mutex::try_lock() ( recursive_mutex, + recursive_timed_mutex, timed_mutex) +
  • this_fiber::sleep_for()
  • this_fiber::sleep_until()
  • +
  • + this_fiber::yield() +
  • this_fiber::interruption_point()
  • diff --git a/doc/html/fiber/performance.html b/doc/html/fiber/performance.html index 7f860a92..908e4d12 100644 --- a/doc/html/fiber/performance.html +++ b/doc/html/fiber/performance.html @@ -70,7 +70,7 @@

    - 955 ns + 1.1 µs

    @@ -146,7 +146,7 @@

    - 1.1 µs + 1.3 µs

    @@ -172,311 +172,6 @@ - -

    - 32 µs -

    - - -

    - 2.4 µs -

    - - - - -
    -

    Table 1.5. Scaling of creating and joining

    -
    ----- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    -

    - average of -

    -
    -

    - thread -

    -
    -

    - fiber -

    -
    -

    - 10 -

    -
    -

    - 50.65 µs -

    -
    -

    - 3.76 µs -

    -
    -

    - 50 -

    -
    -

    - 52.99 µs -

    -
    -

    - 2.78 µs -

    -
    -

    - 100 -

    -
    -

    - 50.44 µs -

    -
    -

    - 2.45 µs -

    -
    -

    - 500 -

    -
    -

    - 45.19 µs -

    -
    -

    - 2.91 µs -

    -
    -

    - 1000 -

    -
    -

    - 42.59 µs -

    -
    -

    - 3.60 µs -

    -
    -

    - 5000 -

    -
    -

    - 42.30 µs -

    -
    -

    - 4.57 µs -

    -
    -

    - 10000 -

    -
    -

    - 41.07 µs -

    -
    -

    - 4.21 µs -

    -
    -
    -

    - Using internally atomics by applying BOOST_FIBER_USE_ATOMICS. -

    -
    -

    Table 1.6. Overhead of creating and joining

    -
    ------ - - - - - - - - - - - - -
    -

    - thread -

    -
    -

    - fiber -

    -
    -

    - tbb -

    -
    -

    - qthread -

    -
    -

    - 31 µs -

    -
    -

    - 1.1 µs -

    -
    -

    - 570 ns -

    -
    -

    - 620 ns -

    -
    -
    -
    -

    Table 1.7. Overhead of detach

    -
    ---- - - - - - - - - -
    -

    - thread -

    -
    -

    - fiber -

    -
    -

    - 20 µs -

    -
    -

    - 3.2 µs -

    -
    -
    -
    -

    Table 1.8. Overhead of yield

    -
    ---- - - - - - - - - -
    -

    - thread -

    -
    -

    - fiber -

    -
    -

    - 38 µs -

    -
    -

    - 1.3 µs -

    -
    -
    -
    -

    Table 1.9. Overhead of waiting on a future

    -
    ---- - - - - -
    -

    - thread -

    -
    -

    - fiber -

    -

    32 µs @@ -491,7 +186,7 @@


    -

    Table 1.10. Scaling of creating and joining

    +

    Table 1.5. Scaling of creating and joining

    @@ -638,6 +333,311 @@
    +

    + Using internally atomics by applying BOOST_FIBER_NO_ATOMICS. +

    +
    +

    Table 1.6. Overhead of creating and joining

    +
    ++++++ + + + + + + + + + + + + +
    +

    + thread +

    +
    +

    + fiber +

    +
    +

    + tbb +

    +
    +

    + qthread +

    +
    +

    + 31 µs +

    +
    +

    + 955 ns +

    +
    +

    + 570 ns +

    +
    +

    + 620 ns +

    +
    +
    +
    +

    Table 1.7. Overhead of detach

    +
    ++++ + + + + + + + + +
    +

    + thread +

    +
    +

    + fiber +

    +
    +

    + 20 µs +

    +
    +

    + 3.2 µs +

    +
    +
    +
    +

    Table 1.8. Overhead of yield

    +
    ++++ + + + + + + + + +
    +

    + thread +

    +
    +

    + fiber +

    +
    +

    + 38 µs +

    +
    +

    + 1.1 µs +

    +
    +
    +
    +

    Table 1.9. Overhead of waiting on a future

    +
    ++++ + + + + + + + + +
    +

    + thread +

    +
    +

    + fiber +

    +
    +

    + 32 µs +

    +
    +

    + 2.4 µs +

    +
    +
    +
    +

    Table 1.10. Scaling of creating and joining

    +
    +++++ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +

    + average of +

    +
    +

    + thread +

    +
    +

    + fiber +

    +
    +

    + 10 +

    +
    +

    + 50.65 µs +

    +
    +

    + 3.76 µs +

    +
    +

    + 50 +

    +
    +

    + 52.99 µs +

    +
    +

    + 2.78 µs +

    +
    +

    + 100 +

    +
    +

    + 50.44 µs +

    +
    +

    + 2.45 µs +

    +
    +

    + 500 +

    +
    +

    + 45.19 µs +

    +
    +

    + 2.91 µs +

    +
    +

    + 1000 +

    +
    +

    + 42.59 µs +

    +
    +

    + 3.60 µs +

    +
    +

    + 5000 +

    +
    +

    + 42.30 µs +

    +
    +

    + 4.57 µs +

    +
    +

    + 10000 +

    +
    +

    + 41.07 µs +

    +
    +

    + 4.21 µs +

    +
    +



    [1] diff --git a/doc/html/index.html b/doc/html/index.html index 24cd412a..36e8b891 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -71,7 +71,7 @@

    - +

    Last revised: June 19, 2015 at 19:37:16 GMT

    Last revised: June 21, 2015 at 08:51:19 GMT


    diff --git a/include/boost/fiber/condition.hpp b/include/boost/fiber/condition.hpp index f82cbebe..cc114b03 100644 --- a/include/boost/fiber/condition.hpp +++ b/include/boost/fiber/condition.hpp @@ -80,10 +80,6 @@ public: // was stored inside schedulers's waiting-queue detail::scheduler::instance()->wait( lk); - // this fiber was notified and resumed - // check if fiber was interrupted - this_fiber::interruption_point(); - // lock external again before returning lt.lock(); } catch (...) { @@ -130,9 +126,6 @@ public: status = cv_status::timeout; } - // check if fiber was interrupted - this_fiber::interruption_point(); - // lock external again before returning lt.lock(); } catch (...) { diff --git a/src/fiber_manager.cpp b/src/fiber_manager.cpp index 52635033..78bd3f09 100644 --- a/src/fiber_manager.cpp +++ b/src/fiber_manager.cpp @@ -12,9 +12,10 @@ #include #include "boost/fiber/algorithm.hpp" -#include "boost/fiber/fiber_context.hpp" #include "boost/fiber/detail/scheduler.hpp" #include "boost/fiber/exceptions.hpp" +#include "boost/fiber/fiber_context.hpp" +#include "boost/fiber/interruption.hpp" #include "boost/fiber/round_robin.hpp" #ifdef BOOST_HAS_ABI_HEADERS @@ -152,6 +153,10 @@ fiber_manager::wait_until( std::chrono::high_resolution_clock::time_point const& run(); // fiber is resumed + // this fiber was notified and resumed + // check if fiber was interrupted + this_fiber::interruption_point(); + return std::chrono::high_resolution_clock::now() < timeout_time; } @@ -166,6 +171,10 @@ fiber_manager::yield() { // switch to another fiber run(); // fiber is resumed + + // this fiber was notified and resumed + // check if fiber was interrupted + this_fiber::interruption_point(); } void @@ -188,6 +197,10 @@ fiber_manager::join( fiber_context * f) { run(); // fiber is resumed + // this fiber was notified and resumed + // check if fiber was interrupted + this_fiber::interruption_point(); + BOOST_ASSERT( f->is_terminated() ); }