ref: 38727e953df2c11f5600ea6f3142ec4366fce3cf
parent: c0c0b95a971cc5da839e7453ac3c7c069b5f20cd
author: Ori Bernstein <ori@eigenstate.org>
date: Fri Jul 27 20:03:47 EDT 2018
Allocate condvar waiters on heap. It solves crashes on plan 9, because plan 9 keeps separate stacks in different procs.
--- a/lib/thread/condvar.myr
+++ b/lib/thread/condvar.myr
@@ -1,3 +1,5 @@
+use std
+
use "atomic"
use "common"
use "mutex"
@@ -35,23 +37,23 @@
const condwait = {cond
var mtx = cond._mtx
var lock = &cond._lock
- var waiter = [.sem = mksem(0)]
+ var waiter = std.mk([.sem = mksem(0)])
mtxlock(lock)
match cond._waitq
| Zptr:
- waiter.prev = &waiter
- cond._waitq = &waiter
+ waiter.prev = waiter
+ cond._waitq = waiter
| q:
waiter.prev = q.prev
- waiter.prev.next = &waiter
- q.prev = &waiter
+ waiter.prev.next = waiter
+ q.prev = waiter
;;
mtxunlock(lock)
mtxunlock(mtx)
semwait(&waiter.sem)
-
+ std.free(waiter)
mtxlock(mtx)
}