From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: "guile-user@gnu.org" <guile-user@gnu.org>
Subject: Re: Passing objects between threads
Date: Thu, 15 Sep 2016 21:37:25 +0200 [thread overview]
Message-ID: <CAMFYt2bkU7fG1Mzn7keYPcequ6+R9qJ2F4c7hUx6jAc_U4_Gdw@mail.gmail.com> (raw)
In-Reply-To: <CAMFYt2aYtp8v15NbuGijwYL2VgK_mqa_CBuXJUcELpN+WFqtNg@mail.gmail.com>
>
> 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
> (λ ()
> (channel-fold
> (λ (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!
> (λ ()
> (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 could
> remain responsive. (I also think that this interface would be nice with
> time-constrained optimization algorithms, so that they could make the best
> 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!
prev parent reply other threads:[~2016-09-15 19:37 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-10 9:37 Passing objects between threads Panicz Maciej Godek
2016-09-10 10:35 ` Diogo F. S. Ramos
2016-09-10 11:18 ` Chaos Eternal
2016-09-10 19:30 ` Panicz Maciej Godek
2016-09-10 19:29 ` Panicz Maciej Godek
2016-09-10 14:30 ` Chris Vine
2016-09-10 20:16 ` Panicz Maciej Godek
2016-09-10 21:36 ` Chris Vine
2016-09-11 18:34 ` Andy Wingo
2016-09-12 19:58 ` Panicz Maciej Godek
2016-09-12 23:10 ` Chris Vine
2016-09-15 19:37 ` Panicz Maciej Godek [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAMFYt2bkU7fG1Mzn7keYPcequ6+R9qJ2F4c7hUx6jAc_U4_Gdw@mail.gmail.com \
--to=godek.maciek@gmail.com \
--cc=guile-user@gnu.org \
--cc=wingo@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).