Bug 9005 – std.concurrency.spawn should allow `void delegate(Args) shared` for new Tid
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-11-12T05:14:00Z
Last change time
2013-02-05T12:54:37Z
Assigned to
nobody
Creator
zan77137
Comments
Comment #0 by zan77137 — 2012-11-12T05:14:19Z
This code should be allowed:
--------------
import core.atomic, core.thread;
import std.concurrency;
import core.sync.barrier;
class Foo
{
shared int a = 0;
void bar(shared Barrier barrier) shared
{
while (1)
{
Thread.sleep(dur!"msecs"(10));
if (a.atomicLoad() > 100)
break;
}
(cast()barrier).wait();
}
void countup() shared
{
foreach (i; 0..200)
{
Thread.sleep(dur!"msecs"(10));
a.atomicStore(i);
}
}
}
void main()
{
auto barrier = new Barrier(2);
auto foo = new Foo;
spawn(&foo.bar, cast(shared)barrier);
foo.countup();
barrier.wait();
}
--------------
The Foo.bar is thread-safe. So, making new Tid by spawn with the shared member function is no problem.
Comment #1 by github-bugzilla — 2012-11-19T08:33:45Z