[dmd-concurrency] synchronized, shared, and regular methods inside the same class

Álvaro Castro-Castilla alvaro.castro.castilla at gmail.com
Wed Jan 6 07:41:28 PST 2010


> Your comparison of normal threading and STM is interesting. You say: "with
> STM you could just read a snapshot of the data". This implies that an
> immutable snapshot of the data exists, which implies some sort of
> copy-on-write where the simulation copies the data every time it changes. It
> won't stop the simulation in order to access the data, but it'll likely make
> it perform slower with all those allocations. It's really a tradeoff between
> data immutability and mutability. To access mutable data, you need a lock;
> not so for immutable data.
>
> So while I agree that supporting transactions would be great, I'm not sure
> how great it'd be for your use case. Especially since if you allocate a lot
> of memory for immutable data, the GC will kick in more often and lock the
> world anyway.
>
> Message passing, where you could subscribe and unsubscribe to various parts
> of the simulation data, could be a good solution because then the simulation
> thread has to create copies of only what has been requested.
>
>
Well, in case you don't care that all the snapshot shows the same time step
for all agents,  there won't be a big performance impact.

On the other hand, I think a nice combination to look at is Clojure's
concurrency model:

"While Vars <http://clojure.org/Vars> ensure safe use of mutable storage
locations via thread *isolation*, transactional references (Refs) ensure
safe *shared* use of mutable storage locations via a software transactional
memory <http://en.wikipedia.org/wiki/Software_transactional_memory> (STM)
system. Refs are bound to a single storage location for their lifetime, and
only allow mutation of that location to occur within a transaction."

>From http://clojure.org/refs

However, I believe a similar effect can be achieve with message passing.

[At this point I received Andrei's post]. It's right to concentrate on
message passing then. Just wanted to bring it into discussion, and know some
points of view.

Best Regards,

Álvaro Castro-Castilla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/dmd-concurrency/attachments/20100106/24dab9e6/attachment.htm>


More information about the dmd-concurrency mailing list