From 2c16beb9421197cc2d3e910e15d8f0fc5c0e9e18 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Sat, 18 May 2019 11:05:16 -0400 Subject: [PATCH] cs & threads: fix plumber flushing interleaved with addition A plumber is supposed to gather all callbacks before running any of them so that callbacks added by a callback are not run. --- racket/src/thread/plumber.rkt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/racket/src/thread/plumber.rkt b/racket/src/thread/plumber.rkt index 3269b3dc08..03ec67eb7f 100644 --- a/racket/src/thread/plumber.rkt +++ b/racket/src/thread/plumber.rkt @@ -43,10 +43,14 @@ (plumber-flush-all/wrap p (lambda (proc h) (proc h)))) (define (plumber-flush-all/wrap p app) - (for ([(h proc) (in-hash (plumber-callbacks p))]) - (app proc h)) - (for ([(h proc) (in-hash (plumber-weak-callbacks p))]) - (app proc h))) + ;; Spec requires getting all callbacks before running any + (define procs+hs + (for*/list ([cbs (in-list (list (plumber-callbacks p) + (plumber-weak-callbacks p)))] + [(h proc) (in-hash cbs)]) + (cons proc h))) + (for ([proc+h (in-list procs+hs)]) + (app (car proc+h) (cdr proc+h)))) (define/who (plumber-flush-handle-remove! h) (check who plumber-flush-handle? h)