[gambit-list] output ports created with ##open-predefined not being garbage collected

Marc Feeley feeley at iro.umontreal.ca
Fri Apr 10 16:16:23 EDT 2020


> On Apr 10, 2020, at 1:59 PM, Jörg F. Wittenberger <Joerg.Wittenberger at softeyes.net> wrote:
> 
> Background:
> 
> Since when I'm using this ##open-predefined and have on my list to ask
> why this seems not to integrate into gambit's threading as good as I
> had hoped for.
> 
> Nevertheless Marcs suggestion to use open-tcp-server does not work for
> me.  I really need a unix domain socket.  Actually an abstract socket
> on Linux.  No way around.  :-/
> 
> But I'd like it to block the calling thread on input.  Which did not
> work out for me.  (There is lambdanative and Android in the mix too, but
> my current _guess_ is that neither is to blame here.)

On POSIX systems, you can use ##open-predefined to create a port from a file descriptor.

Then, when you want to wait for input to be available you can call ##wait-input-port with that port.  This is the definition in lib/_io.scm:

(define-prim (##wait-input-port port)                                           
                                                                                
  ;; The thread will wait until there is data available to read on the          
  ;; port's device or the port's timeout is reached.  The value #f is           
  ;; returned when the timeout is reached.  The value #t is returned            
  ;; when there is data available to read on the port's device or the           
  ;; thread was interrupted (for example with thread-interrupt!).               

  …)

This is fully integrated with the thread system, so it only blocks the calling thread.  Note also that you can use input-port-timeout-set! if you want to block for a limited time.

Marc





More information about the Gambit-list mailing list