Concurrency Read/Write and Pure

Adam Adam at anizi.com
Wed Nov 30 20:23:39 PST 2011


Howdy.

So, I'm reading through "The D Programming Language" book, and I had
some questions on concurrency in D, and maybe with some emphasis on
programming in general.

I present my question with a hypothetical case:
 I have two threads and, ideally, one structure. The structure is
large enough that passing it in its entirety is non-trivial, and
that a synchronized understanding of the data at any given point of
time between the two threads is ideal (that is, it's not desirable
for one thread to update another with changes to the structure).
 One thread writes / makes changes to the structure's contents.
 The other only reads the structure's contents (as well as its
topology)

Now, I could make this structure global with respect to both threads
(shared), which would introduce the need to synchronize access to it
for both threads (using synchronized, mutexes, etc).

However, for all intents and purpose, the writing thread "owns" the
data - it's the only thread allowed to make changes to it.

Given that, and the guarantees made by "pure," is there a scheme in
D to fit this explicit one-thread-reads, one-thread-writes scenario
that doesn't require a mutex / synchronization between the two
(since only one will be changing it)?


More information about the Digitalmars-d-learn mailing list