[Issue 6747] Implicitly allowing objects which contain delegates to be shared/immutable can cause races
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jan 24 06:14:00 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=6747
mhh <maxhaton at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |maxhaton at gmail.com
Severity|enhancement |normal
--- Comment #1 from mhh <maxhaton at gmail.com> ---
Still a problem BUT @safe does catch the problem in it.
https://d.godbolt.org/z/Px5aTM
------------------
import std.algorithm;
import std.stdio;
import std.traits;
class Foo //@safe can catch the bug with ref
{
immutable this(ref int _i)
{
dg = (){++_i;};
}
void delegate() dg;
}
immutable Foo f;
int notShared;
shared static this()
{
f = new immutable Foo(notShared);
}
void sharedInc(immutable Foo x)
{
x.dg();
}
void main()
{
import std.stdio;
import std;
f.dg();
f.dg();
f.dg();
auto file1Task = task!sharedInc(f);
file1Task.executeInNewThread();
// Read bar.txt in parallel.
sharedInc(f);
// Get the results of reading foo.txt.
file1Task.yieldForce;
}
--
More information about the Digitalmars-d-bugs
mailing list