unsynchronized access to primitive variables
Dejan Lekic
dejan.lekic at gmail.com
Sun May 20 06:51:44 PDT 2012
On Saturday, 19 May 2012 at 08:16:39 UTC, luka8088 wrote:
> Hello to all,
>
> I would like to know if D guarantees that access to primitive
> variable is atomic ?
>
> I was looking for any source of information that says anything
> about unsynchronized access to primitive variables. What I want
> to know is if it is possible (in any way and any OS / hardware)
> for the following code to output anything other then 1 or 2:
>
> import std.stdio;
> import core.thread;
>
> void main () {
> int value = 1;
> (new Thread({ value = 2; })).start();
> writeln(value);
> }
>
> Thanks !
This proggy will always print "1" because writeln() prints the
value from the main thread. Spawned thread will have own value.
Remember TLS is the default storage.
More information about the Digitalmars-d-learn
mailing list