[Issue 9005] New: std.concurrency.spawn should allow `void delegate(Args) shared` for new Tid

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Nov 12 05:14:24 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=9005

           Summary: std.concurrency.spawn should allow `void
                    delegate(Args) shared` for new Tid
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: zan77137 at nifty.com


--- Comment #0 from SHOO <zan77137 at nifty.com> 2012-11-12 05:14:19 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list