From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Re: Passing objects between threads Date: Thu, 15 Sep 2016 21:37:25 +0200 Message-ID: References: <87mvjeb80n.fsf@pobox.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1473968373 30894 195.159.176.226 (15 Sep 2016 19:39:33 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 15 Sep 2016 19:39:33 +0000 (UTC) Cc: "guile-user@gnu.org" To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Sep 15 21:39:29 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 1bkcVA-00069D-T4 for guile-user@m.gmane.org; Thu, 15 Sep 2016 21:39:17 +0200 Original-Received: from localhost ([::1]:37039 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkcV8-00044Z-WD for guile-user@m.gmane.org; Thu, 15 Sep 2016 15:39:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48726) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkcUm-00043y-E4 for guile-user@gnu.org; Thu, 15 Sep 2016 15:38:54 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkcUi-0006Zh-9u for guile-user@gnu.org; Thu, 15 Sep 2016 15:38:51 -0400 Original-Received: from mail-wm0-f50.google.com ([74.125.82.50]:38605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkcUh-0006RL-Vh for guile-user@gnu.org; Thu, 15 Sep 2016 15:38:48 -0400 Original-Received: by mail-wm0-f50.google.com with SMTP id 1so2264571wmz.1 for ; Thu, 15 Sep 2016 12:38:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=cMGr7QKYog13oX5UYNIr5RhheLStm5nbdOkkZiW0S+k=; b=vIukocAXmdfk0wCq4qKmgVP397x8t6vlhAx8BUJ8dH0lVAxIMeiIRqLMM4VbJXPpCZ E7xKcRs0ezJ7Aq5kyS7EF93uSrqUJuQe2ThUtEZis0P4RsjVSKVol+c09bZYMOYBKHu/ PoLS1xqyf85WFhiLDqa8bPKd2ImO90G1cEvKKOM1cqJEU5YRKs03cegnG1W+t7DjtP2s WFfoLFXgBONnkNL6TlYp7R5iLFJGpBfICK1hhl9N++pkcFgDVoHLuVMmRFWvyKAPY4wP ppdZuElS1N4gwV4T5+idAEzw28nptIHGaS2fUKYtB7M4XbjxAxk7iQVc7YD07sbOHRqM ZrEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=cMGr7QKYog13oX5UYNIr5RhheLStm5nbdOkkZiW0S+k=; b=nNdwDDnLr989DLL0XNy3oNKmqg1f3bQDmcYMYFaA2/Sq018jkK6+Gei9hARlMcq29I 1RNEYHnYpcM/MBwJMjYHDB/HHL8soNO/Hkj4GnxAkiA3XJJ3H+K2aGhTyMbzonk1wJDB DQDFM7NG4kLzghjbiw3qaDr9Xw/ajewgVrVSLj9WicXS8DK2iD7o2MoqFhtFyk4fqhV8 4ARZEoPz9Vm6r8Cf7bZu1el4+Kdro944FzQY74Yy2QQAYfeGCCSw7VLRWaX0ojAOgr4h TDFGani6Oisf4K7r4xzaFmLdpyakGZq7KtVRqixKrRFYfUaRDFD74gF0qp7ztaCWxc64 nTmQ== X-Gm-Message-State: AE9vXwPuON6prqeDlSctHSpGA1P+05P5UEG27fAos0xdxh57n3A/jroydx4HPBfNVyjSGaz7g9ZxZ5mtrVU5fg== X-Received: by 10.28.91.11 with SMTP id p11mr4489950wmb.98.1473968246013; Thu, 15 Sep 2016 12:37:26 -0700 (PDT) Original-Received: by 10.80.165.46 with HTTP; Thu, 15 Sep 2016 12:37:25 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.50 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 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:12912 Archived-At: > > I could of course communicate between the threads using a global variable > and assignment, but this is nasty. Instead I thought of the following > interface: I would like to have two functions, let's call them "exposed" > and "snapshot". The first one would behave like identity (or values), > except that its evaluation would cause the snapshot value of the current > thread to be set. The second function would be used to retrieve the > snapshot value, so that it could be accessed from other threads. > > For example, I could define the evolution thread in the following way: > > (define evolution > (call-with-new-thread > (=CE=BB () > (channel-fold > (=CE=BB (state action) > (let ((state* (update state #;with action))) > (exposed state*))) > initial-state > EVENT-QUEUE)))) > > Then, I could access the state variable using the snapshot procedure, so > that -- for example -- I could use it in the drawing routine: > > (set-display-procedure! > (=CE=BB () > (draw! (visualization (snapshot evolution))))) > > What I would like about that solution is that even if the world was > updated much faster than the drawing routine could handle, the system cou= ld > remain responsive. (I also think that this interface would be nice with > time-constrained optimization algorithms, so that they could make the bes= t > known solution available at any time) > > However, the problem is that -- while procedures have their properties -- > there seems to be nothing similar in the realm of threads. Normally in > similar cases I could use a thread-indexed hash table, but in the context > of multi-threading it would probably need to be protected by a mutex, and > it would likely slow things down. > > Any suggestions? > I have found that SRFI-18 provides a pair thread-specific/thread-specific-set! that allows me to implement that interface. Hooray!