Skip to content

Commit 95a64d6

Browse files
committed
runtime: fix coroutine handle race during sleep
1 parent 1509be4 commit 95a64d6

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

std/runtime/proc.jule

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,8 +1217,9 @@ async fn sleep(dur: sleepDuration) {
12171217
mut c := m.c
12181218
when := nanotime() + dur
12191219
mut t := timer.new(when, nil, uintptr(&c), 0)
1220+
m.pp.timers.mu.lock()
12201221
m.pp.timers.push(t)
1221-
park(&c, 0, reasonSleep).await
1222+
park(&c, uintptr(&m.pp.timers.mu), reasonSleep).await
12221223
}
12231224

12241225
// Destroys all retired coroutine frames for the current worker thread.

std/runtime/timer.jule

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,13 @@ impl timerheap {
9494
}
9595

9696
// Inserts a timer into the heap.
97+
// Timer lock must be held.
9798
#disable nilptr
9899
fn push(mut *self, mut t: &timer) {
99-
t.mu.lock()
100100
t.theap = unsafe { (&timerheap)(self) }
101101
t.index = len(self.data)
102102
self.data = append(self.data, t)
103103
self.siftup(t.index)
104-
t.mu.unlock()
105104
}
106105

107106
// Removes and returns the earliest timer.

0 commit comments

Comments
 (0)