From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Aleix_Conchillo_Flaqu=C3=A9?= Newsgroups: gmane.lisp.guile.user Subject: Re: guile fibers - looking for adivce Date: Sat, 5 Sep 2020 18:19:49 -0700 Message-ID: References: <20200906024757.58dd34cd@interia.pl> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23167"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Jan Wielkiewicz Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sun Sep 06 03:20:15 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kEjLr-0005v6-OS for guile-user@m.gmane-mx.org; Sun, 06 Sep 2020 03:20:15 +0200 Original-Received: from localhost ([::1]:40480 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kEjLq-0001oC-QS for guile-user@m.gmane-mx.org; Sat, 05 Sep 2020 21:20:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:59468) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kEjLh-0001nA-DE for guile-user@gnu.org; Sat, 05 Sep 2020 21:20:05 -0400 Original-Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]:38911) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kEjLf-00063B-8V for guile-user@gnu.org; Sat, 05 Sep 2020 21:20:05 -0400 Original-Received: by mail-lf1-x12a.google.com with SMTP id y11so5778962lfl.5 for ; Sat, 05 Sep 2020 18:20:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=YbGuui0LClZurIwh3pJwYrsRsAt7J9vGabaBdAlX+QA=; b=fox6F9A5zIhz1MIXmcbxpImJVw0WsXb8XjSQBaOQ+1Z8F6YWrOlA0c8TUvlD7mDXI9 opMD48AbmHHdQ6HVsJQqLAjle4T/kpggnw0ugT1Cy95SC9AnbeDBa/nMpG3OhAtoZBvO W6XOyxInOEAGqOoqHm6Pd3bIcg057c9V4BjETLjk7mB3L7K7HUhNygZ5OkypOMQPGUAP 8TnF6pSVx7mS2bm5ytoARIFr3x0iZYfE/AcKrYDrV5BKhGk3kF3thCSD6b9sqQbuJyPs zZF52qvtrTy++UBmcNyiGMe/PbqQcdbqHxVA3EEOGuXGieBVquMu/2IbJq63Sh1+JFTa 9t8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=YbGuui0LClZurIwh3pJwYrsRsAt7J9vGabaBdAlX+QA=; b=JP7tsbk15f8k04mdlJrYzznH7hDyiwzzu77vWP9OWiCHo68fsAtW1U1XE1ajdinQKd bLkwq7aTWc+BXPrLCNoBokMiptujdFlIJGkTuY3cx3P96r/OLwbpEbDv9yDu9wscsxwP s6WXsjGdO1RovcDDtEYWhyysSNVYvcmeqHn82N/SRCI3TF801Yv2GdpaGku1og+k2onC nxuPeSuvY5ohJ3Ba4BntpNFsDW3EEtukWn6j0P3ISP1jGsPIzJTmdopPy0asQ0Q37rF3 vptSlWnpRbHLQ4JcnXSFePC6vUXu1vbtQz8htVwMOvv0BQq0YBvZh8h0In/0eyMcF4KP wINQ== X-Gm-Message-State: AOAM532rua7+wbwElKQ/oLF7wWC1Jfu8vnQ4kVI7vL93cc7BVXMdnZw4 QJYRuztEQ4JCLI1SJ9VMxHp+GclHwF++4plcijY= X-Google-Smtp-Source: ABdhPJxxPHqfoOZR5PS06OcvQjrL0FI+s8jSwb5gQfZPOij3WqQezG+TqS5xQ446P0HcswWlGe669AiUR2HWbUZhNkA= X-Received: by 2002:ac2:5597:: with SMTP id v23mr7086794lfg.5.1599355200560; Sat, 05 Sep 2020 18:20:00 -0700 (PDT) In-Reply-To: <20200906024757.58dd34cd@interia.pl> Received-SPF: pass client-ip=2a00:1450:4864:20::12a; envelope-from=aconchillo@gmail.com; helo=mail-lf1-x12a.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16866 Archived-At: 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