Skip to content

Commit a6c4287

Browse files
committed
runtime: don't call sleepTicks with a negative duration
There are rare cases where this can happen, see for example #4568
1 parent f9f439a commit a6c4287

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

builder/sizes_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func TestBinarySize(t *testing.T) {
4141
// This is a small number of very diverse targets that we want to test.
4242
tests := []sizeTest{
4343
// microcontrollers
44-
{"hifive1b", "examples/echo", 4568, 280, 0, 2268},
45-
{"microbit", "examples/serial", 2868, 388, 8, 2272},
46-
{"wioterminal", "examples/pininterrupt", 6104, 1484, 116, 6832},
44+
{"hifive1b", "examples/echo", 4580, 280, 0, 2268},
45+
{"microbit", "examples/serial", 2888, 388, 8, 2272},
46+
{"wioterminal", "examples/pininterrupt", 6124, 1484, 116, 6832},
4747

4848
// TODO: also check wasm. Right now this is difficult, because
4949
// wasm binaries are run through wasm-opt and therefore the

src/runtime/scheduler.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -230,13 +230,15 @@ func scheduler(returnAtDeadlock bool) {
230230
println("--- timer waiting:", tim, tim.whenTicks())
231231
}
232232
}
233-
sleepTicks(timeLeft)
234-
if asyncScheduler {
235-
// The sleepTicks function above only sets a timeout at which
236-
// point the scheduler will be called again. It does not really
237-
// sleep. So instead of sleeping, we return and expect to be
238-
// called again.
239-
break
233+
if timeLeft > 0 {
234+
sleepTicks(timeLeft)
235+
if asyncScheduler {
236+
// The sleepTicks function above only sets a timeout at
237+
// which point the scheduler will be called again. It does
238+
// not really sleep. So instead of sleeping, we return and
239+
// expect to be called again.
240+
break
241+
}
240242
}
241243
continue
242244
}

0 commit comments

Comments
 (0)