diff --git a/examples/priority.cpp b/examples/priority.cpp index e18d3d5b..2b861af1 100644 --- a/examples/priority.cpp +++ b/examples/priority.cpp @@ -18,6 +18,7 @@ public: } ~Verbose() { + std::cout << desc << ' ' << stop << std::endl; } private: @@ -93,16 +94,15 @@ public: // we're handed a new context*, put it at the end of the fibers // with that same priority. In other words: search for the first fiber // in the queue with LOWER priority, and insert before that one. - if ( rqueue_.empty() ) { - rqueue_.push_back( * f); - } else { - rqueue_t::iterator e( rqueue_.end() ); - for ( rqueue_t::iterator i( rqueue_.begin() ); i != e; ++i) { - if ( properties( & ( * i) ).get_priority() < f_priority) { - rqueue_.insert( i, * f); - } + rqueue_t::iterator i( rqueue_.begin() ), e( rqueue_.end() ); + for ( ; i != e; ++i) { + if ( properties( & ( * i) ).get_priority() < f_priority) { + break; } } + // Now, whether or not we found a fiber with lower priority, + // insert this new fiber here. + rqueue_.insert( i, * f); //<- std::cout << "awakened(" << props.name << "): "; diff --git a/examples/work_sharing.cpp b/examples/work_sharing.cpp index a58bd5cb..442e5a08 100644 --- a/examples/work_sharing.cpp +++ b/examples/work_sharing.cpp @@ -31,10 +31,11 @@ private: static std::mutex mutex_; typedef std::unique_lock lock_t; - // Reserve a separate, thread-specific slot for this thread's main fiber. - // It would be Bad News for thread B to retrieve and attempt to execute - // thread A's main fiber. This slot might be empty (nullptr) or full (== - // context::main_fiber()): pick_next() must only return the main fiber's + // Reserve a separate, scheduler-specific slot for this thread's main + // fiber. When we're passed the main fiber, stash it there instead of in + // the shared queue: it would be Bad News for thread B to retrieve and + // attempt to execute thread A's main fiber. This slot might be empty + // (nullptr) or full: pick_next() must only return the main fiber's // context* after it has been passed to awakened(). boost::fibers::context* main_fiber;