[Issue 2162] New: Access violation when threads run closures
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 22 15:20:24 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2162
Summary: Access violation when threads run closures
Product: D
Version: 2.016
Platform: PC
OS/Version: Windows
Status: NEW
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: bugzilla at digitalmars.com
ReportedBy: bartosz at relisoft.com
Passing closures to threads might be considered an error, but the current
thread implementation virtualy encourages it. The program below behaves
erratically--the starting value of x and y inside thread functions is random
and, at leas in my environment, the program access violates. (I'm not sure how
reproducible it is).
void test(ref Thread thr1, ref Thread thr2)
{
int x, y;
int run1()
{
writeln("Run1 ", x);
for(int i = 0; i < 100000; ++i)
++x;
writeln("End Run1 ", x);
return 0;
}
int run2()
{
writeln("Run2 ", y);
for(int i = 0; i < 100000; ++i)
++y;
writeln("End Run2 ", y);
return 0;
}
thr1 = new Thread(&run1);
thr2 = new Thread(&run2);
}
void main()
{
try
{
Thread thr1, thr2;
test(thr1, thr2);
thr1.start();
thr2.start();
thr1.wait();
thr2.wait();
}
catch(Exception e)
{
writeln ("Exception in main: ", e.toString);
}
}
--
More information about the Digitalmars-d-bugs
mailing list