From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: dfsr@riseup.net (Diogo F. S. Ramos) Newsgroups: gmane.lisp.guile.user Subject: Re: Passing objects between threads Date: Sat, 10 Sep 2016 07:35:57 -0300 Message-ID: <87h99odotu.fsf@riseup.net> References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1473503798 31769 195.159.176.226 (10 Sep 2016 10:36:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2016 10:36:38 +0000 (UTC) Cc: "guile-user@gnu.org" To: Panicz Maciej Godek Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Sep 10 12:36:34 2016 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bifeC-0007XI-1B for guile-user@m.gmane.org; Sat, 10 Sep 2016 12:36:32 +0200 Original-Received: from localhost ([::1]:33915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bifeA-0005mo-2K for guile-user@m.gmane.org; Sat, 10 Sep 2016 06:36:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bifdo-0005mS-2g for guile-user@gnu.org; Sat, 10 Sep 2016 06:36:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bifdj-00022I-1h for guile-user@gnu.org; Sat, 10 Sep 2016 06:36:07 -0400 Original-Received: from mx1.riseup.net ([198.252.153.129]:48553) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bifdi-00022D-M3 for guile-user@gnu.org; Sat, 10 Sep 2016 06:36:02 -0400 Original-Received: from piha.riseup.net (unknown [10.0.1.163]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client CN "*.riseup.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK)) by mx1.riseup.net (Postfix) with ESMTPS id 5CCFF1A0392; Sat, 10 Sep 2016 10:36:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1473503761; bh=Fyh/2UpSkdhqWvsXeCYsG8v/VEm6WKMU6AwXscaL264=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=o/tA634IDyOjaeQxRmrF999Yn9Z5EUWN3PtP9ePQvhR2rYoyT9IKsis3JXOnJoQeW yA4wCKuEZScE7NtPZIHXkMQlUjxsMdSA/jT0Z+hPdsf1k+pItjHHihMEyIgDMkXdp1 nVBppuBwqyoy7WcrO/Xu1NkRpxGHB8DGg4Hi6IM8= Original-Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: dfsr) with ESMTPSA id 5BC8B1C035A In-Reply-To: (Panicz Maciej Godek's message of "Sat, 10 Sep 2016 11:37:55 +0200") X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 198.252.153.129 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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:12893 Archived-At: --=-=-= Content-Type: text/plain > Hi, > is there any easy way to create a channel (queue) that could be used to > communicate between threads? In particular, if the queue is empty, I would > like the consumer to wait until something appears in it (pretty much like > the channels in Clojure) I don't know about Clojure, but I've written the attached program a while ago. It worked for my purposes, but it wasn't tested much. --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=channel.scm Content-Transfer-Encoding: base64 Ozs7IGNoYW5uZWwuc2NtIC0tLSBEYXRhIHN0cnVjdHVyZSB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