From ec72f5df457905be024478322ad3c40f31717bcb Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 18 Sep 2019 14:00:54 -0600 Subject: [PATCH] cs & thread: avoid accumulating post-atomic callbacks Only one instance of each callback is needed. Allowing them to pile up is inefficient, and possibly it can trigger a reaction that causes even more to pile up. --- racket/src/thread/atomic.rkt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/racket/src/thread/atomic.rkt b/racket/src/thread/atomic.rkt index 1f052db6bf..fbf9911720 100644 --- a/racket/src/thread/atomic.rkt +++ b/racket/src/thread/atomic.rkt @@ -105,7 +105,14 @@ ;; no race with the scheduler (define (add-end-atomic-callback! cb) (host:disable-interrupts) - (end-atomic-callback (cons cb (end-atomic-callback))) + (define all-cbs (end-atomic-callback)) + (let loop ([cbs all-cbs]) + (cond + [(eq? cbs 0) + (end-atomic-callback (cons cb all-cbs))] + [else + (unless (eq? (car cbs) cb) + (loop (cdr cbs)))])) (host:enable-interrupts)) ;; ----------------------------------------