unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Chris Vine <vine35792468@gmail.com>
To: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>
Cc: Guile User <guile-user@gnu.org>
Subject: Re: Guile fibers return values
Date: Sun, 5 Jan 2020 21:45:55 +0000	[thread overview]
Message-ID: <20200105214555.60e424b8cf86456e188c75f6@gmail.com> (raw)
In-Reply-To: <547672e4-30f7-2783-f3d5-199417a71c98@posteo.de>

On Sun, 5 Jan 2020 19:22:14 +0100
Zelphir Kaltstahl <zelphirkaltstahl@posteo.de> wrote:
> I think the decision tree calculations, which I want to parallelize, are
> not I/O related. However, I am not quite sure I understand the whole
> suspendable port thing, but here is what I think it is:
> 
> When some I/O happens in a fiber, the fiber is still able to pause
> (suspend, yield, …) at that point, because the suspendable ports work in
> such a way, that no harm is done in doing so. Later the I/O work can be
> resumed (woken up from suspension). This quality had to be built into
> Guile first, before fibers were able to take advantage of it.
> 
> Is this correct?

Yes, suspendable ports were first implemented in guile-2.2.  They are
used by 8-sync (https://www.gnu.org/software/8sync/), guile-a-sync2
(https://github.com/ChrisVine/guile-a-sync2/wiki) and fibers, and
possibly by other libraries.

The basic arrangement is that if a port's file descriptor is not ready,
then its continuation is saved, and is resumed by the scheduler when it
becomes ready.  fibers use epoll rather than POSIX select or poll for
this.

> But I do not understand, why this is not the case with normal OS
> threads. Maybe it can be done but is not convenient or difficult to get
> right, to work with suspendable ports, when not using the fibers library?
>
> And why is simple-format not "suspendable-port-safe"? (What does a
> procedure need to do, in order to be "suspendable-port-safe"?)

simple-format does not suspend as it is implemented in C in libguile and
its continuation is not available to scheme code.  There is a
list of those of guile's i/o procedures which do (and which do not)
suspend here, in the second and third paragraphs, although it does not
mention format/simple-format:
https://github.com/ChrisVine/guile-a-sync2/wiki/await-ports
(That library has nothing to do with fibers, but as mentioned above it
happens to use suspendable ports for similar purposes): 

None of this is likely to be relevant to your use case.

[snip]
> With the parallel forms, isn't it the case, that at each call of such a
> form, new OS threads are created? In this case it might be a good idea
> to create a fibers scheduler and reuse it, if that is possible, so that
> I do not need to create my own process pool kind of thingy.

guile's parallel forms are implemented using futures, which use an
internal thread pool according to this:
https://www.gnu.org/software/guile/docs/master/guile.html/Futures.html#Futures

"Internally, a fixed-size pool of threads is used to evaluate futures,
such that offloading the evaluation of an expression to another thread
doesn’t incur thread creation costs. By default, the pool contains one
thread per available CPU core, minus one, to account for the main
thread."

Chris



  reply	other threads:[~2020-01-05 21:45 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-05  1:30 Guile fibers return values Zelphir Kaltstahl
2020-01-05 12:33 ` Chris Vine
2020-01-05 12:58   ` Zelphir Kaltstahl
2020-01-05 14:28     ` Chris Vine
     [not found]     ` <20200105142358.4ad96d15a23a0b947b2d55e3@gmail.com>
2020-01-05 18:22       ` Zelphir Kaltstahl
2020-01-05 21:45         ` Chris Vine [this message]
2020-01-06 19:42           ` Zelphir Kaltstahl
2020-01-06 21:14             ` Chris Vine
2020-01-06 21:47               ` John Cowan
2020-01-06 22:45                 ` Zelphir Kaltstahl
2020-01-07  1:36                   ` John Cowan
  -- strict thread matches above, loose matches on Subject: below --
2020-01-04 22:49 Zelphir Kaltstahl
2020-01-05  2:42 ` John Cowan
2020-01-05 12:46   ` Zelphir Kaltstahl
2020-01-14 10:59 ` Amirouche Boubekki
2020-01-15  0:04   ` Zelphir Kaltstahl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200105214555.60e424b8cf86456e188c75f6@gmail.com \
    --to=vine35792468@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=zelphirkaltstahl@posteo.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).