From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.user Subject: Re: Guile fibers return values Date: Sun, 5 Jan 2020 12:33:29 +0000 Message-ID: <20200105123329.5019662bdf1895a4164faf62@gmail.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="136429"; mail-complaints-to="usenet@blaine.gmane.org" To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Jan 05 13:33:33 2020 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1io564-000ZLc-8z for guile-user@m.gmane.org; Sun, 05 Jan 2020 13:33:32 +0100 Original-Received: from localhost ([::1]:41590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1io563-0002xU-4K for guile-user@m.gmane.org; Sun, 05 Jan 2020 07:33:31 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55522) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1io55l-0002xM-IX for guile-user@gnu.org; Sun, 05 Jan 2020 07:33:14 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1io55k-00060L-HV for guile-user@gnu.org; Sun, 05 Jan 2020 07:33:13 -0500 Original-Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:53855) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1io55k-0005z1-9S for guile-user@gnu.org; Sun, 05 Jan 2020 07:33:12 -0500 Original-Received: by mail-wm1-x330.google.com with SMTP id m24so12253666wmc.3 for ; Sun, 05 Jan 2020 04:33:11 -0800 (PST) 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=jrJORgOTfkLfl1uD02oaHVC51ca/DexJrGx5gRXDNdM=; b=fL7B/wyMh9ocp6WpvROeGmnPsgTk5yHapMzgXhvWVFw3QUEQlDehTnMpHrKlQt/4Lp m7jFbOA9l1S4swL7GmPHciCR9Nme4eJGYgFKgyOQhFcltTw6+1V+q4v5OeC5oj3okoI1 FUBt0DfbS1E3X7HTw+a3N5kszVp0HpKhOgCrpuKutB6ftxLCYnJniHABHT1KVjbEW3hf Sm0LxbJbRBEWTJKlWjY6P3o4cHB31o+kOpFnz2QSqVhlthNoI3Vko1k67bmjAAL2a48Q lfLgocIT9eGgX4eKddq2YMeF7Cfj91TP0tmI/6dbk8KYk2foQeCInKlI4TWmB2H8vrZp dlww== 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=jrJORgOTfkLfl1uD02oaHVC51ca/DexJrGx5gRXDNdM=; b=Q+OzOE5DkhwvEBz7ci1nujoZShvjCg0SJaMX8Mb6CkrUbYyKR0ub8EiyfSQXJjY4M1 wUxLKOucuYvgd0MYLDNbzfX9ch0eHdFYxcsTSW+Sqb9hhM4E+fP/q3G7TVLt+vOGo09+ 64EAOE8O3p0api63jYUeBy6J7xqfqj1yBvSZi8v0daDoh/faXbLcUZbZfAWVrHGEYomk 2m+zMy/gBQWllMzxa2pBnaL7DD1DbmrbiE4+a8EYnNCNkisL6Gcm+CQr0VtYc9pqbt3d BE5oAXmzzsiMtJxKsyU/WdjIjl4ReVL2W6J/+yAGhxuKHNg7LXh2HyCVc+BeWJi2tnmE m5CA== X-Gm-Message-State: APjAAAW0NvXjUPizUsVxmydA2Tkeas7hEIz2fuloz3GYQg3bbTLgV8nj vMADW0K/wrPBHW+VTV+RW1H/GOKT X-Google-Smtp-Source: APXvYqzKt5GxlMcQB/XmlgTRhft6oL9VIm3lFMYIqaV2BmIZggvv2baLRcLGMkPxXDwA5hvVNdMzSQ== X-Received: by 2002:a7b:c769:: with SMTP id x9mr28542998wmk.26.1578227590347; Sun, 05 Jan 2020 04:33:10 -0800 (PST) Original-Received: from bother.homenet ([91.110.243.20]) by smtp.gmail.com with ESMTPSA id x11sm70471796wre.68.2020.01.05.04.33.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jan 2020 04:33:09 -0800 (PST) Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with SMTP id CCA0526030A for ; Sun, 5 Jan 2020 12:33:29 +0000 (GMT) In-Reply-To: X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::330 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.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15989 Archived-At: On Sun, 5 Jan 2020 02:30:06 +0100 Zelphir Kaltstahl wrote: [snip] > This way of communication between the fiber and the main process seems > in the style of Racket's places. Except that I can send normal > procedures / lambdas to the fiber, which is great on a single machine, > while I need to send serializable lambdas to Racket places (and I have > not gotten to do that yet). > > Is there a restriction on the kind of lambdas I can send on a channel as > I did in the example above? I may well be missing your point, mainly because I don't know what you mean by "the main process" - all the fibers are part of the same process, and can be run in the same native thread if you want. run-fibers runs what amounts to a scheduler and does not return until the thunk passed to it returns. So if by "the main proccess" you mean the thunk which is running on a fiber scheduler, then you know it has finished when run-fibers returns, after which you can execute what other non-fiber code you want to execute. run-fibers will return the value (if any) returned by the thunk which it runs. Within the thunk run by run-fibers, you normally synchronize using channels. At it's absolute simplest it can be this: (display (run-fibers (lambda () (let ((channel (make-channel))) (spawn-fiber (lambda () (sleep 1) ;; do some work (put-message channel "hello world"))) (simple-format #t "~a~%" (get-message channel)) "finished\n")))) Here the "main" thunk (the one passed to run-fibers which returns "finished\n") will not finish until the fiber thunk has finished, because of the wait on the channel. If you spawn multiple fibers and the "main" thunk does not wait for the fibers like this, and you therefore need to ensure additionally that run-fibers does not return until all the fiber thunks have finished, you can set the drain argument of run-fibers to #t. Probably in that case your "main" thunk will not return a meaningful value. You say you want "to parallelize some algorithm". If that is your main aim, consider guile's parallel forms of parallel, let-par and friends. Chris