dynamic extent and threads Per Bothner (28 Sep 2017 14:01 UTC)
Re: dynamic extent and threads Arthur A. Gleckler (28 Sep 2017 16:51 UTC)
Re: dynamic extent and threads Marc Nieper-Wißkirchen (29 Sep 2017 08:36 UTC)
Re: dynamic extent and threads Shiro Kawai (30 Sep 2017 23:07 UTC)

dynamic extent and threads Per Bothner 28 Sep 2017 14:00 UTC

How would one efficiently implement first-class dynamic extends in the presence of threads?

An efficient way to implement parameters is to use a per-thread hash map
from parameter objects to bindings.  This has the advantage that accessing or
updating a parameter can be done without locking.  It means that the map has to
copied when a new thread is created, but that can be done without locking, and
creating a thread is expected to be a moderately heavy-weight.

Such as strategy makes current-dynamic-extent and with-dynamic-extent somewhat expensive,
since you have to copy the hash-map.  Which means creating a srfi-155 promises would be
fairly expensive.  Any clever ideas for ameliorating that?

A future is basically a promise using a separate thread, in which case the
copying happens anyway.

(In Kawa, parameters are implemented using ThreadLocal objects - specifically
InheritableThreadLocal objects, which are standard classes in the Java "platform".
A ThreadLocal is implemented using a per-thread map from ThreadLocal objects to values.
A InheritableThreadLocal initializes a new thread's bindings with the binding
from the parent thread.)

--
	--Per Bothner
xxxxxx@bothner.com   http://per.bothner.com/