Skip to content

Commit 91bed14

Browse files
committed
green: Fix a scheduler assertion on yielding
This commit fixes a small bug in the green scheduler where a scheduler task calling `maybe_yield` would trip the assertion that `self.yield_check_count > 0` This behavior was seen when a scheduler task was scheduled many times successively, sending messages in a loop (via the channel `send` method), which in turn invokes `maybe_yield`. Yielding on a sched task doesn't make sense because as soon as it's done it will implicitly do a yield, and for this reason the yield check is just skipped if it's a sched task. I am unable to create a reliable test for this behavior, as there's no direct way to have control over the scheduler tasks. cc rust-lang#12666, I discovered this when investigating that issue
1 parent 80f92f5 commit 91bed14

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libgreen/sched.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,20 @@ impl Scheduler {
832832
}
833833

834834
pub fn maybe_yield(mut ~self, cur: ~GreenTask) {
835+
// It's possible for sched tasks to possibly call this function, and it
836+
// just means that they're likely sending on channels (which
837+
// occasionally call this function). Sched tasks follow different paths
838+
// when executing yield_now(), which may possibly trip the assertion
839+
// below. For this reason, we just have sched tasks bail out soon.
840+
//
841+
// Sched tasks have no need to yield anyway because as soon as they
842+
// return they'll yield to other threads by falling back to the event
843+
// loop. Additionally, we completely control sched tasks, so we can make
844+
// sure that they never execute more than enough code.
845+
if cur.is_sched() {
846+
return cur.put_with_sched(self)
847+
}
848+
835849
// The number of times to do the yield check before yielding, chosen
836850
// arbitrarily.
837851
rtassert!(self.yield_check_count > 0);

0 commit comments

Comments
 (0)