[racket] Detecting that a place channel is unreachable

From: Eric Dobson (eric.n.dobson at gmail.com)
Date: Sat Dec 7 02:53:04 EST 2013

Is there a way to determine if a place channel is unreachable? My
experiments with will executors seem to show that they trigger even if
the place channel is reachable from another place. Is there a way to
determine that all other places don't have access to the value, I
assume that it has to be possible because otherwise memory would leak,
but maybe getting triggers based of of it would be hard.

My goal is to have two places sharing a channel, and one stop sending
messages across if the other one is provable not listening. I can make
it so that it can turn it off manual, but I'm looking to see if I can
get it to work if the listener just lets the channel get gc'd.


Testing program:
#lang racket/base

(require racket/place)

(define (holder)
  (place chan
    (let loop ([v #f])
      (define v2 (sync chan))
      (place-channel-put chan v)
      (collect-garbage)
      (loop v2))))


(module+ main
  (define other (holder))
  (define exec (make-will-executor))
  (define exec-thread
    (thread
      (lambda ()
        (let loop ()
          (will-execute exec)
          (loop)))))
  (define in
    (let-values ([(in out) (place-channel)])
      (place-channel-put other out)
      (sync other)
      (will-register exec out
        (lambda (v) (printf "~a was deleted~n" v)))
      in))
  (collect-garbage)
  ;; Let will execute
  (sleep 1))

Posted on the users mailing list.