On Wed, Oct 2, 2019 at 8:42 AM Matthew Flatt <mfl...@cs.utah.edu> wrote:
>
> At Tue, 1 Oct 2019 23:52:05 -0400, David Storrs wrote:
> > ; main dispatcher loop in the server.  Receives messages, dispatches
> > to child thread for processing
>
> > 2) This WOULD work:
> > (let loop ()
> >     (define msg (get-next-message)) ; e.g. (file-info "sha1-hash-of-file-X")
> >     (hash-set! channels msg ch)
> >     (thread (thunk (process-file msg ch)))))
> >     (loop))
> >
> > In this case, 'msg' is still reachable from the processing thread, so
> > it remains in the weak hash until the processing thread terminates, at
> > which point it is removed from the weak hash and the corresponding
> > channel is GC'd.
>
> It depends on `process-file`. If `process-file` retains `msg` until it
> is otherwise done, then yes. But if `process-file` ignores the argument
> for `msg` or only uses it for the first part of its work, then `msg`
> can get GCed before `process-file` returns.

If process-file looked like this:

(define (process-file msg ch)
  (define the-hash-str (file-info-hash msg))
  ...do stuff with the-hash-str...
)

I think this would mean that msg could get GC'd as early as right
after the first line, but it's not guaranteed as to when it would be
GC'd.  Yes?

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKofmwcrQNVYkWNyd%3DdiPy2gzXBOgpHgYyUiLJ6_iMtrHHw%40mail.gmail.com.

Reply via email to