unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Aleix Conchillo Flaqué" <aconchillo@gmail.com>
To: Jan Wielkiewicz <tona_kosmicznego_smiecia@interia.pl>
Cc: guile-user <guile-user@gnu.org>
Subject: Re: guile fibers - looking for adivce
Date: Mon, 7 Sep 2020 17:25:38 -0700	[thread overview]
Message-ID: <CA+XASoX4H=gq83pnZFTSkwqv2vWowCMMK+qqGVzS_f=CjE6hwQ@mail.gmail.com> (raw)
In-Reply-To: <20200907185627.72eca419@interia.pl>

Hi Jan,

On Mon, Sep 7, 2020 at 7:56 AM Jan Wielkiewicz <
tona_kosmicznego_smiecia@interia.pl> wrote:

> Hi!
>
> Dnia 2020-09-05, o godz. 18:19:49
> Aleix Conchillo Flaqué <aconchillo@gmail.com> napisał(a):
>
> > Hi!
> >
> > On Sat, Sep 5, 2020 at 3:48 PM Jan Wielkiewicz <
> > tona_kosmicznego_smiecia@interia.pl> wrote:
> >
> > I believe sharing the same object by the two fibers defeats the
> > purpose of message passing, because with the way you are doing it you
> > find exactly the problem you are having and the only way to fix this
> > is by using mutexes. That is, you are trying to use fibers as you
> > would use regular threads sharing a resource. Instead, there should
> > probably be a main fiber (that holds the object) and send messages
> > (with the data needed from the object) to 2 other fibers (those would
> > be your methods A and B).
> I see, thank you for explanation. This allowed me to understand the
> problem doesn't lie in the way I was trying to implement my messaging
> through fibers, but rather in the way I was using GOOPS - my custom
> method for initializing slots called next-method after doing everything
> what caused some weird problems with allocation.
>
> Are threads and mutexes worth using, if there are fibers already?
> I know I'll have to learn this eventually, to fully master programming,
> but I'm not sure if there's a great advantage over fibers.
>
>
I don't think mixing threads and fibers is a good idea, so I would stick
with fibers. However, you might still want to use mutexes for certain
things.

This might be useful: https://github.com/golang/go/wiki/MutexOrChannel

As they say, sometimes you start over-using channels because it's fun, but
a mutex might just be simpler. So if you find yourself getting with too
many channels think if a mutex would be easier, and the other way around,
if using the mutex is getting too hairy try to think if a channel would be
easier.

I would suggest reading about Go routines and channels, since it's the same
as fibers and there's a lot of information out there.

> >
> > I haven't used fibers extensively, but I've used Go quite a bit which
> > follows the same pattern of channels and message passing and this is
> > how you would do it.
> >
> > Also, the fibers manual also suggests this approach:
> > https://github.com/wingo/fibers/wiki/Manual#33-mutation
> Yeah, I've read the manual like three times already, but Andy is
> somethimes writing sentences from outer space, including the GOOPS
> manual. This isn't the level of English I'm currently on.
> I guess I'll write some self-explaining examples of GOOPS after I fully
> understand it.
>
>
To be honest, I've never used GOOPS so things might be a bit more
complicated there, I don't know. But it sounds like you have two options:

- Create a fiber with the object and pass data from the object using
channels to other fibers. Then return data to the main fiber (or the fiber
that has the object) through a channel and update your object.
- Make the object global and have fibers that update the object. In this
case you would need to use mutexes.

Or maybe you find another way?

> That said, I might be wrong though.
> >
> > Hope this helps,
> >
> > Aleix
>
> Thanks for explanation, this made my thinking much cleaner. I can get
> back to experimenting now!
>
>
Cool, let us know!
Aleix


  reply	other threads:[~2020-09-08  0:25 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-06  0:47 guile fibers - looking for adivce Jan Wielkiewicz
2020-09-06  0:42 ` Zelphir Kaltstahl
2020-09-07 16:34   ` Jan Wielkiewicz
2020-09-06  1:19 ` Aleix Conchillo Flaqué
2020-09-07 16:56   ` Jan Wielkiewicz
2020-09-08  0:25     ` Aleix Conchillo Flaqué [this message]
2020-09-08  7:48       ` Chris Vine
2020-09-08 17:56         ` Aleix Conchillo Flaqué
2020-09-10  1:05       ` Jan Wielkiewicz
2020-09-06 19:26 ` Chris Vine

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='CA+XASoX4H=gq83pnZFTSkwqv2vWowCMMK+qqGVzS_f=CjE6hwQ@mail.gmail.com' \
    --to=aconchillo@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=tona_kosmicznego_smiecia@interia.pl \
    /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).