www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Strange struct/atomicLoad behaviour

reply d coder <dlang.coder gmail.com> writes:
--047d7b2ee283e5036504cfb62e71
Content-Type: text/plain; charset=ISO-8859-1

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();
}

--047d7b2ee283e5036504cfb62e71
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Greetings<div><br></div><div>Here is a small piece of code that uses atomic=
Load on a shared data, and behaves strange. Any clues whether this is a pro=
blem with atomicLoad(druntime) or with the DMD itself. I see the problem wi=
th the 2.060 release as well as with the github&#39;s current snapshot.</di=
v>

<div><br></div><div>When I compile and run the code on my 64bit Ubuntu 12.1=
0 machine, it prints out=A0</div><div><div>42</div><div>4294967296</div></d=
iv><div><br></div><div>Now, if I comment out the constructor of the Foo str=
uct (which anyway I am not using), I get the right result that is=A0</div>

<div>42</div><div>42</div><div><br></div><div>Any clues?</div><div><br></di=
v><div>Regards</div><div>- Puneet</div><div><br></div><div><div>import core=
.atomic;</div><div><br></div><div>struct Foo {</div><div>=A0 public ulong _=
s =3D 0;</div>

<div>=A0 public this (ulong s) =A0{</div><div>=A0 =A0 this._s =3D s;</div><=
div>=A0 }</div><div>}</div><div><br></div><div>auto foo () {</div><div>=A0 =
import std.stdio;</div><div>=A0 shared static Foo bar;</div><div>=A0 bar._s=
 =3D 42;</div><div>

=A0 writeln(bar._s);</div><div>=A0 shared Foo frop =3D atomicLoad(bar);</di=
v><div>=A0 writeln(frop._s);</div><div>=A0 return frop;</div><div>}</div><d=
iv><br></div><div>void main() {</div><div>=A0 foo();</div><div>}</div></div=
<div><br>

</div> --047d7b2ee283e5036504cfb62e71--
Nov 30 2012
next sibling parent "Maxim Fomin" <maxim maxim-fomin.ru> writes:
This is another bug with structures. Consider posting this to 
bugzilla.
Nov 30 2012
prev sibling parent d coder <dlang.coder gmail.com> writes:
--f46d042f9e0c3f9e4f04cfb7852e
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Nov 30, 2012 at 7:41 PM, Maxim Fomin <maxim maxim-fomin.ru> wrote:

 This is another bug with structures. Consider posting this to bugzilla.

Thanks for confirming. I have posted this to Bugzilla. Regards - Puneet --f46d042f9e0c3f9e4f04cfb7852e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Fri, Nov 30, 2012 at 7:41 PM, Maxim F= omin <span dir=3D"ltr">&lt;<a href=3D"mailto:maxim maxim-fomin.ru" target= =3D"_blank">maxim maxim-fomin.ru</a>&gt;</span> wrote:<br><blockquote class= =3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd= ing-left:1ex"> This is another bug with structures. Consider posting this to bugzilla.<br> </blockquote></div><br><div><br></div><div>Thanks for confirming. I have po= sted this to Bugzilla.</div><div><br></div><div>Regards</div><div>- Puneet<= /div> --f46d042f9e0c3f9e4f04cfb7852e--
Nov 30 2012