Skip to content

Commit 678b031

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 cad7d24 commit 678b031

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
@@ -831,6 +831,20 @@ impl Scheduler {
831831
}
832832

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

0 commit comments

Comments
 (0)