From b77731617c14f9956c0bceb7796d26bd972de1ba Mon Sep 17 00:00:00 2001 From: Robby Findler Date: Sat, 2 Aug 2014 09:10:33 -0500 Subject: [PATCH] add a will-executor example --- .../scribblings/reference/memory.scrbl | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/pkgs/racket-pkgs/racket-doc/scribblings/reference/memory.scrbl b/pkgs/racket-pkgs/racket-doc/scribblings/reference/memory.scrbl index 7f9a6ffbb5..aac2acf27e 100644 --- a/pkgs/racket-pkgs/racket-doc/scribblings/reference/memory.scrbl +++ b/pkgs/racket-pkgs/racket-doc/scribblings/reference/memory.scrbl @@ -139,6 +139,25 @@ A will executor is @tech{ready for synchronization} when @racket[will-execute] would not block; @resultItself{will executor}. +These examples show how to run cleanup actions when +no synchronization is necessary. It simply runs the registered +executors as they become ready in another thread. +@mz-examples[(define an-executor (make-will-executor)) + (eval:alts (void + (thread + (λ () + (let loop () + (will-execute an-executor) + (loop))))) + (void)) + (define (executor-proc v) (printf "a-box is now garbage\n")) + (define a-box-to-track (box #f)) + (will-register an-executor a-box-to-track executor-proc) + (eval:alts (collect-garbage) (void)) + (set! a-box-to-track #f) + (eval:alts (collect-garbage) (executor-proc))] + + @defproc[(make-will-executor) will-executor?]{ Returns a new will executor with no managed values.}