guile-user
[Top][All Lists]
Advanced

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

Re: guile fibers - looking for adivce


From: Aleix Conchillo Flaqué
Subject: Re: guile fibers - looking for adivce
Date: Sat, 5 Sep 2020 18:19:49 -0700

Hi!

On Sat, Sep 5, 2020 at 3:48 PM Jan Wielkiewicz <
tona_kosmicznego_smiecia@interia.pl> wrote:

> Hello,
>
> I'm still on my way of integrating Guile Fibers and GOOPS, but I
> encountered some weird behavior.
> Say I have an object with with one slot being a vector and two methods
> accessing the vector concurrently/parallelly. The methods
> accessing/editing the vector are time consuming and are meant to be ran
> frequently. Assuming I would like to run the methods on separate
> fibers, how do I make sure the state of the object doesn't
> suddenly change during execution of a method? I would like the methods
> to be able to edit the state of the object, but in a cooperative manner.
>
> The weird behavior I've encountered is that sometimes when running the
> first method (A) and right after starting the second method (B), the
> method B tries to access the vector before the method A finishes its
> job. What should I do to make accessing the vector cooperatively, yet
> to run the time consuming on separate fibers for concurrency?
>
> I was thinking about implementing slots in objects as sending and
> receiving messages instead of regular variables, but still there were
> some problems with the object state.
>
> Could someone explain me what should I do?
>
>
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 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

That said, I might be wrong though.

Hope this helps,

Aleix


reply via email to

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