Shouldn't spawn work with __gshared?
Andrej Mitrovic
none at none.none
Wed Apr 20 15:10:35 PDT 2011
Before you give me a lecture on thread safety, sometimes I have to test code on-the-fly and __gshared comes in really handy when working with C codebases.
Now, here's something that won't fly:
import std.concurrency;
class Foo { }
__gshared Foo foo;
void main()
{
foo = new Foo();
spawn(&bar, foo);
}
void bar(ref Foo)
{
}
Error:
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\concurrency.d(326): Error: static assert "Aliases to mutable thread-local data not allowed."
spawnGshared.d(13): instantiated from here: spawn!(Foo)
foo isn't thread local.
bar could use the global directly, yes, but this was just a test case. In my real code the bar function is defined in a different module and doesn't see the foo instance since it's in module scope of the main module.
Anyway, yeah I'll translate this to a thread-safe version, of course. But this looks like a bug to me.
More information about the Digitalmars-d-learn
mailing list