guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: anyone define port types?


From: Andy Wingo
Subject: Re: anyone define port types?
Date: Mon, 20 Jun 2016 09:34:26 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux)

On Mon 20 Jun 2016 08:45, Chris Vine <address@hidden> writes:

> For simplicity, let's say you have a file watch in the glib event loop
> which has made a non-blocking read of the first byte of a multi-byte
> UTF-8 character, and the suspendable-ports implementation is in use
> because it is a non-blocking read of a TCP socket.  (It could be
> something different: there may be a non-blocking read request for a
> complete line of text which has so far only partially been satisfied,
> but the partially complete character is the easiest example to deal
> with.)  The read request is therefore in read-waiter waiting for a
> complete UTF-8 byte sequence to arrive.  On the current hypothesis,
> read-waiter comprises a procedure which is suspended on a prompt
> waiting for an event to occur in the glib main loop which will cause
> it to resume, comprising the file descriptor becoming ready which will
> satisfy the read request.  But while suspended in read-waiter, this
> prompt would have to service any user event sources which might become
> ready in the glib main loop, not just the particular file descriptor
> in question becoming ready.

I must not be communicating clearly because this is definitely not what
I am proposing.  The prompt doesn't service anything, and it's just the
one user-space thread which is suspended, and when it suspends, it
suspends back to the main loop which runs as usual, timers and all.

                        prompt
   /------\ /------------\|/-----------\ /------------\ /----------\
   | main --> run-thread -|>(user code)-->  read-char -->  waiter  |
   | loop | |            |||           | |            | |          |
   \------/ \------------/|\-----------/ \------------/ \--|-------/
                          ^                                |
                           \-------------------------------/
   stack grows this way ->

The current-read-waiter aborts to a prompt.  That prompt is instated
when the thread is run or resumed.  When you abort to that prompt, you
add the FD to the poll set / main loop / *, remember the delimited
continuation, and return to the main loop.  When the fd becomes readable
or the gsource fires or whatever, you reinstate the delimited
continuation via a new invocation of run-thread (prompt and all).

> My approach on the other hand does not nest events from the glib main
> loop in this way.

"Nesting events" should not be a thing you have to do.

Andy



reply via email to

[Prev in Thread] Current Thread [Next in Thread]