Strange struct/atomicLoad behaviour
d coder
dlang.coder at gmail.com
Fri Nov 30 05:14:04 PST 2012
Greetings
Here is a small piece of code that uses atomicLoad on a shared data, and
behaves strange. Any clues whether this is a problem with
atomicLoad(druntime) or with the DMD itself. I see the problem with the
2.060 release as well as with the github's current snapshot.
When I compile and run the code on my 64bit Ubuntu 12.10 machine, it prints
out
42
4294967296
Now, if I comment out the constructor of the Foo struct (which anyway I am
not using), I get the right result that is
42
42
Any clues?
Regards
- Puneet
import core.atomic;
struct Foo {
public ulong _s = 0;
public this (ulong s) {
this._s = s;
}
}
auto foo () {
import std.stdio;
shared static Foo bar;
bar._s = 42;
writeln(bar._s);
shared Foo frop = atomicLoad(bar);
writeln(frop._s);
return frop;
}
void main() {
foo();
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20121130/449f7876/attachment.html>
More information about the Digitalmars-d
mailing list