cs & thread: repair for custodian sync witth future host thread

This commit is contained in:
Matthew Flatt 2019-07-09 13:37:24 -06:00
parent 9c0a3abfdb
commit 8c052df959

View File

@ -496,6 +496,9 @@
;; ---------------------------------------- ;; ----------------------------------------
(define-syntax-rule (keep-trying e)
(let loop () (unless e (loop))))
(define (start-worker w) (define (start-worker w)
(define s (current-scheduler)) (define s (current-scheduler))
(define th (define th
@ -504,12 +507,14 @@
(current-future 'worker) (current-future 'worker)
(host:mutex-acquire (scheduler-mutex s)) (host:mutex-acquire (scheduler-mutex s))
(let loop () (let loop ()
(or (box-cas! (worker-sync-state w) 'idle 'running) (keep-trying
(box-cas! (worker-sync-state w) 'pending 'running)) (or (box-cas! (worker-sync-state w) 'idle 'running)
(box-cas! (worker-sync-state w) 'running 'running)
(box-cas! (worker-sync-state w) 'pending 'running)))
(cond (cond
[(worker-die? w) ; worker was killed [(worker-die? w) ; worker was killed
(host:mutex-release (scheduler-mutex s)) (host:mutex-release (scheduler-mutex s))
(box-cas! (worker-sync-state w) 'running 'idle)] (box-cas! (worker-sync-state w) 'running 'dead)]
[(scheduler-futures-head s) [(scheduler-futures-head s)
=> (lambda (f) => (lambda (f)
(deschedule-future f) (deschedule-future f)
@ -522,8 +527,9 @@
(loop))] (loop))]
[else [else
;; wait for work ;; wait for work
(or (box-cas! (worker-sync-state w) 'pending 'idle) (keep-trying
(box-cas! (worker-sync-state w) 'running 'idle)) (or (box-cas! (worker-sync-state w) 'pending 'idle)
(box-cas! (worker-sync-state w) 'running 'idle)))
(host:condition-wait (scheduler-cond s) (scheduler-mutex s)) (host:condition-wait (scheduler-cond s) (scheduler-mutex s))
(loop)]))))) (loop)])))))
(set-worker-pthread! w th)) (set-worker-pthread! w th))