From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: guile fibers - looking for adivce Date: Tue, 8 Sep 2020 08:48:23 +0100 Message-ID: <20200908084823.ce82ef1386b3bc0609599f8a@gmail.com> References: <20200906024757.58dd34cd@interia.pl> <20200907185627.72eca419@interia.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9129"; mail-complaints-to="usenet@ciao.gmane.io" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Tue Sep 08 09:48:29 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 1kFYMf-0002Ds-S4 for guile-user@m.gmane-mx.org; Tue, 08 Sep 2020 09:48:29 +0200 Original-Received: from localhost ([::1]:48812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFYMe-0008P7-Ut for guile-user@m.gmane-mx.org; Tue, 08 Sep 2020 03:48:28 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52712) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFYMS-0008Om-Pr for guile-user@gnu.org; Tue, 08 Sep 2020 03:48:16 -0400 Original-Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]:42879) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFYMR-0005ol-0z for guile-user@gnu.org; Tue, 08 Sep 2020 03:48:16 -0400 Original-Received: by mail-wr1-x432.google.com with SMTP id c18so17979341wrm.9 for ; Tue, 08 Sep 2020 00:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wLXA0/1rFTNgiKSUS2GhW9aX6p/7tHA/yNVEX6utepY=; b=vVivRoP4MSkY8e9clj8eQLaDTPHZIxYg40//8mvxLHRG1+1uYKN7UjjRCfXaLDK3U1 lWHZgqHYAqUvpxULcmF9ef4qae9P+SggKEFmIvErQ1ICAvmxkh3V8+/vKWx2y6kZ2s5n R4LKaORmWnEzkQjERouFEWGnjUoC3bAX9mIBUgN7phiQ18RqqKd0n510Ij9mKyIXGoFX RF8HtSjH/BpJxxOoSMbWrglKsMRC/R0gxkI0cs9DimGvhXUMjjdQ3kzlt4I5sG5MAG/R bHvJ4IogZW4b+Zw2K7AgsIspzG0K168dc+z5vfDipR32yZcwBxwFpR20ili9rMAI+HBJ g0zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wLXA0/1rFTNgiKSUS2GhW9aX6p/7tHA/yNVEX6utepY=; b=EPdNnMUtbOpbhqgUynqEBwU/irqDQHY/5i6vzAP9vYvUApd/z2XIiDwmY5mpcPLTZh 3kz1hjLLrtKuywQswMOfYUn5nfAz1iKf7pUikTizdmvOMV9vI4xfziZJyZmRCsJgdl2P K847Lv+LxYpQMOurLJ13vuQR2+WzLvCpI6gaoHun6J/CrGhlQnp1rOaCKD5HRogPT/VH ZsNxk7rWIe6uTuZz6rNUdhPCZMDpfueViagQOovjeLGCJjZqh7Oe1MW2Qvx4oTg/yMSr WmKL5aAnkM/q92IfpsmQEU8krKHmh2WsOFQKOG2oLkXa0uDv6gWh4YAO5JYd2YvsB6Ww wMGg== X-Gm-Message-State: AOAM531MJ+UFjn1lleiZKRVDgFvIDafvmQOUtRXPqPvZ7mAeqcAnvHUK dFanw+Th2pJIzFlD9mgo82e098W10X1VpRWQ X-Google-Smtp-Source: ABdhPJxML7F1j6uBXWk/7lKKJvCIx/W3TsuPRkcAGhVzk0A6ufhPeCUg0q+6DEfMQaf2qPQviMKPPQ== X-Received: by 2002:adf:e610:: with SMTP id p16mr27358501wrm.71.1599551292036; Tue, 08 Sep 2020 00:48:12 -0700 (PDT) Original-Received: from bother.homenet ([2002:21b:b8b3:10:156a:4360:8479:890a]) by smtp.gmail.com with ESMTPSA id i6sm36366531wra.1.2020.09.08.00.48.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Sep 2020 00:48:11 -0700 (PDT) Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with SMTP id 7BD52269508 for ; Tue, 8 Sep 2020 08:48:23 +0100 (BST) In-Reply-To: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) Received-SPF: pass client-ip=2a00:1450:4864:20::432; envelope-from=vine35792468@gmail.com; helo=mail-wr1-x432.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: -36 X-Spam_score: -3.7 X-Spam_bar: --- X-Spam_report: (-3.7 / 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_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, NICE_REPLY_A=-1.825, 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-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:16886 Archived-At: On Mon, 7 Sep 2020 17:25:38 -0700 Aleix Conchillo Flaqué wrote: [snip] > 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? The OP should use channels. It is a bad idea to mix mutexes (which are a construct for native OS threads) with fibers, because fibers run as delimited continuations, a group of which may be running on a particular thread. To synchronize fibers, you use channels. Guile's atomic variables (boxes) are available and can be used with fibers because they do not block, but to use them you really need to know what you are doing, just as you do if you are using them in C. Atomic variables do synchronize memory, but they do not provide mutual exclusion (they don't block) and so require expert skills: don't use them if you don't know how to use atomic compare-and-swap correctly. This is what the guile fibers manual has to say: "Guile’s mutexes are an even worse solution with a Fibers system. It is a bad idea for a fiber to grab a Guile mutex, because if the mutex is not available, Guile will suspend not just the fiber that is running but the entire kernel thread. If the mutex is available, the fiber obtains it, cool; but if it the fiber suspends while holding a mutex, that’s bad news. Any fiber trying to acquire a mutex while a suspended fiber from the same thread already has the mutex will result in an error: as Guile thinks that the mutex has already been acquired by the current thread, it detects recursion and bails out. ... "The root of this problem is that Guile associates mutexes with kernel threads, not fibers. It would be possible however to make a Fibers-appropriate implementation of mutexes, but we suggest that users try atomic boxes or channels instead. If you do use mutexes, make sure you disable preemption (possibly by a local call to call-with-blocked-asyncs), and take care to never suspend a fiber while it owns any mutex."