On Tue, 12 May 2009 12:41:50 -0400, dsimcha <dsim...@yahoo.com> wrote:
== Quote from Tomas Lindquist Olsen (tomas.l.ol...@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);