I'm not sure if this is the exact answer to your question, but I hope it helps.

This program shows the content of the two vectors, (i.e.
0000000000000000000011111111111111111111) but when the first vector is
freed it displays "goodbye" in the middle of the sequence. So you can
see when it was released.

You can modify it to peek what job-queue is doing.

Gustavo

(PS: If you use a "list" instead of a "vector", you will get a weird
result, because the head of the list is released as soon as possible,
but the tail is not released until later.)

;--------------
#lang racket

; force some randoms garbage collections
(void (thread
       (lambda ()
         (let loop ()
           (sleep (random 1 3))
           (collect-garbage)
           (loop)))))

; make a will executor to see when something is freed
(define the-executor (make-will-executor))
(void (thread
       (lambda ()
         (let loop ()
           (will-execute the-executor)
           (loop)))))
(define (remember-to-say-goodbye v)
  (will-register the-executor
                 v
                 (lambda (x) (display "goodbye"))))

; display, but wait a moment
(define (display/slow x)
  (sleep .2)
  (display x))

; make a vector that says goodbye when freed
(define (make-polite-vector l v)
  (let ([ret (make-vector l v)])
    (remember-to-say-goodbye ret)
    ret))

;main program
(void (thread
       (lambda ()
         (for ([x (make-polite-vector 20 0)])
           (display/slow x))
         (for ([x (make-vector 20 1)])
           (display/slow x)))))

;--------------


On Wed, Dec 13, 2017 at 3:57 PM, David Storrs <david.sto...@gmail.com> wrote:
> Sorry, bumped 'send' by mistake
>
> Imagine I do this:
>
>     (struct fruit (num))
>     (define (foo) (make-list 100000000 (fruit 7)))
>     (define (bar) (map (compose add1 fruit-num) (foo)))
>
>     (submit-job! (thunk (bar)))
>
> I think that the above is roughly equivalent to doing this:
>
>     (thread (thunk (bar) (sleep <arbitrarily large number>)))
>
> If I'm understanding things correctly, the structs that were created
> in (foo) will be up for garbage collection when (bar) exits, even
> though the worker thread continues to run.  Is that right?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to