2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-16 13:22:17 +00:00

Merge pull request #66 from nat-goodspeed/develop

Fix hang in priority.cpp
This commit is contained in:
Oliver Kowalke
2015-09-10 05:35:51 +02:00
2 changed files with 13 additions and 12 deletions

View File

@@ -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 << "): ";

View File

@@ -31,10 +31,11 @@ private:
static std::mutex mutex_;
typedef std::unique_lock<std::mutex> 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;