dmd 1.045 / 2.030 release

dsimcha dsimcha at yahoo.com
Tue May 12 10:05:40 PDT 2009


== Quote from Robert Jacques (sandford at jhu.edu)'s article
> On Tue, 12 May 2009 12:41:50 -0400, dsimcha <dsimcha at yahoo.com> wrote:
> > == Quote from Tomas Lindquist Olsen (tomas.l.olsen at gmail.com)'s article
> >> Is there a reason for the missing announcement ?
> >> http://digitalmars.com/d/1.0/changelog.html#new1_045
> >> http://www.digitalmars.com/d/2.0/changelog.html#new2_030
> >> and what happened to 1.044 ?
> >> -Tomas
> >
> > Probably because it doesn't quite work yet.  I'm waiting for some crufty
> > old 2.029
> > code to run, so I thought I'd try out shared a little.  Here are the
> > results:
> >
> > import std.stdio, std.perf, core.thread;
> >
> > shared uint foo;
> >
> > void main() {
> >     auto t = new Thread({stuff();});
> >     t.start;
> >     scope pc = new PerformanceCounter;
> >     pc.start;
> >     foreach(i; 0..10_000_000) {
> >         foo++;
> >     }
> >     t.join;
> >     pc.stop;
> >     writeln(pc.milliseconds);
> >     uint bar = foo;
> >     writeln(bar);  // Prints some pseudorandom, wrong number.
> > }
> >
> > void stuff() {
> >     foreach(i; 0..10_000_000) {
> >         foo++;
> >     }
> > }
> >
> > Or is the automatic synchronization of shared variables part not
> > supposed to be
> > implemented yet?
> Bartosz hasn't talked about D's shared system yet. Anyways, what you are
> seeing is a classic read/write race, and is expected even if foo is
> sequential consistent or locked. What you'd need to test is the Peterson
> lock
>
(http://bartoszmilewski.wordpress.com/2008/11/11/who-ordered-sequential-consistency/)
> Remember foo++ ->
> r1 = foo;
> r1++;
> foo = r1;
> So
> lock(foo);
> r1 = foo;
> unlock(foo);
> r1++;
> lock(foo);
> foo = r1;
> unlock(foo);

Yes, but I thought the whole point of shared was to make it impossible to have
these kinds of bugs in your code, i.e. all the synchronization primitives
necessary are supposed to occur below the level of the language abstraction.


More information about the Digitalmars-d-announce mailing list