diff --git a/examples/interrupt.cpp b/examples/interrupt.cpp index fd662a31..01464874 100644 --- a/examples/interrupt.cpp +++ b/examples/interrupt.cpp @@ -31,10 +31,6 @@ int main() try { f.join(); - - std::cout << "done." << std::endl; - - return EXIT_SUCCESS; } catch ( boost::fibers::fiber_interrupted const&) { std::cerr << "interrupted" << std::endl; } @@ -43,5 +39,7 @@ int main() catch (...) { std::cerr << "unhandled exception" << std::endl; } - return EXIT_FAILURE; + std::cout << "done." << std::endl; + + return EXIT_SUCCESS; } diff --git a/src/scheduler.cpp b/src/scheduler.cpp index b28d01a0..a7e2e00d 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -90,17 +90,21 @@ scheduler::~scheduler() noexcept { break; } } - // FIXME -#if 0 // destroy terminated fibers from terminated-queue + tqueue_t::iterator e = tqueue_.end(); for ( tqueue_t::iterator i = tqueue_.begin(); i != e;) { - //BOOST_ASSERT( i->is_terminated() ); - // intrusive_ptr_release( & ( * i) ); // might call ~context() - //i = tqueue_.erase( i); + context * f( & ( * i) ); + BOOST_ASSERT( f->is_terminated() ); + i = tqueue_.erase( i); + BOOST_ASSERT( ! f->state_is_linked() ); + BOOST_ASSERT( ! f->wait_is_linked() ); + BOOST_ASSERT( ! f->yield_is_linked() ); + intrusive_ptr_release( f); // might call ~context() } -#endif - BOOST_ASSERT( wqueue_.empty() ); BOOST_ASSERT( context::active() == main_context_); + BOOST_ASSERT( wqueue_.empty() ); + BOOST_ASSERT( yqueue_.empty() ); + BOOST_ASSERT( 0 == sched_algo_->ready_fibers() ); } void @@ -186,15 +190,17 @@ scheduler::run( context * af) { BOOST_ASSERT_MSG( f->is_ready(), "fiber with invalid state in ready-queue"); // resume fiber f resume_( af, f); - // FIXME -#if 0 // destroy terminated fibers from terminated-queue + tqueue_t::iterator e = tqueue_.end(); for ( tqueue_t::iterator i = tqueue_.begin(); i != e;) { - //BOOST_ASSERT( i->is_terminated() ); - // intrusive_ptr_release( & ( * i) ); // might call ~context() - //i = tqueue_.erase( i); + context * f( & ( * i) ); + BOOST_ASSERT( f->is_terminated() ); + i = tqueue_.erase( i); + BOOST_ASSERT( ! f->state_is_linked() ); + BOOST_ASSERT( ! f->wait_is_linked() ); + BOOST_ASSERT( ! f->yield_is_linked() ); + intrusive_ptr_release( f); // might call ~context() } -#endif return; } else { // no fibers ready to run; the thread should sleep