From 8c052df959c2e8d6a684cffdb366a40a55135b87 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Tue, 9 Jul 2019 13:37:24 -0600 Subject: [PATCH] cs & thread: repair for custodian sync witth future host thread --- racket/src/thread/future.rkt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/racket/src/thread/future.rkt b/racket/src/thread/future.rkt index 12479bd430..f31b10d316 100644 --- a/racket/src/thread/future.rkt +++ b/racket/src/thread/future.rkt @@ -496,6 +496,9 @@ ;; ---------------------------------------- +(define-syntax-rule (keep-trying e) + (let loop () (unless e (loop)))) + (define (start-worker w) (define s (current-scheduler)) (define th @@ -504,12 +507,14 @@ (current-future 'worker) (host:mutex-acquire (scheduler-mutex s)) (let loop () - (or (box-cas! (worker-sync-state w) 'idle 'running) - (box-cas! (worker-sync-state w) 'pending 'running)) + (keep-trying + (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 [(worker-die? w) ; worker was killed (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) => (lambda (f) (deschedule-future f) @@ -522,8 +527,9 @@ (loop))] [else ;; wait for work - (or (box-cas! (worker-sync-state w) 'pending 'idle) - (box-cas! (worker-sync-state w) 'running 'idle)) + (keep-trying + (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)) (loop)]))))) (set-worker-pthread! w th))