www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11309] New: std.concurrency: OwnerTerminated message doesn't work

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309

           Summary: std.concurrency: OwnerTerminated message doesn't work
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: mk krej.cz



Not sure where is the problem, but the thread doesn't end as expected.

------
import core.thread, std.concurrency, std.stdio;

void main()
{
    writeln("starting");
    auto tid = spawn(&worker);
    Thread.sleep(dur!"msecs"(100));
    tid.send(10);
    Thread.sleep(dur!"msecs"(100));
    writeln("finishing");
}

void worker()
{
    for (bool running = true; running; )
    {
        receive(
            (int m) { writeln("Got ", m); },
            (OwnerTerminated unused) { writeln("main ended"); running = false;
}
        );
    }
}
-----

DMD32 D Compiler v2.064-devel-9e9a329
Linux 32.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 20 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



14:26:29 PDT ---
Did this work on earlier versions of dmd?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com



14:29:29 PDT ---
It works in 2.063.2, but gets stuck in git-head. I'm on Win7 x86.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309




If it's any help, try adding the folowing terminate() function and call it at
the end of main(). The thread will end correctly (but the main segfaults). I
was using it like this in 2.063 and it worked. I guess something has changed in
druntime.

extern (C)
{
    // These are for control of termination
    void rt_moduleTlsDtor();
    void thread_joinAll();
    void rt_moduleDtor();
    void gc_term();
    void _STD_critical_term();
    void _STD_monitor_staticdtor();
} /* end extern C */

void terminate()
{
    // Phobos termination (since we can't really make main() return):
    rt_moduleTlsDtor();
    thread_joinAll();
    rt_moduleDtor();
    gc_term();
    version (Posix)
    {
        _STD_critical_term();
        _STD_monitor_staticdtor();
    }

    exit(EXIT_SUCCESS);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 22 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309




This seems to be the offender:

https://github.com/D-Programming-Language/druntime/commit/db772968244bf5af37a81060758a1f266e0b698f

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code dawg.eu
         AssignedTo|nobody puremagic.com        |code dawg.eu



This happens because the OwnerTerminated mechanism is sensible to the order in
which threads are joined.
The regression was introduced with
https://github.com/D-Programming-Language/druntime/pull/600.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 25 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309




13:27:47 PDT ---
What's the solution here? Revert the pull?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 26 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309





 What's the solution here? Revert the pull?
Refixing bug 10976 which was caused by bug 11378. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309




We're taking on a new liability of the runtime here. AFAIK the following
behavior isn't documented anywhere.
Threads are joined in the same order they were created (slightly less strict,
parent threads are joined before their child threads). An argumentation for
this is that a child thread is an owned resource of the parent thread so the
parent thread must have the chance to join or terminate this resource in it's
thread dtor.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309




Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/b73e2c4554db5bb67ceb51adb053e715b2a090b5
fix Issue 11309 - std.concurrency: OwnerTerminated message doesn't work

- add regression test
- Revert "fix Issue 10976 - thread_joinAll after main exit performed too late"

This reverts commit 7d82a57c82f9a5359468680f36aa1026243e6f9e.

Conflicts:
    src/core/runtime.d
    src/rt/dmain2.d

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=11309


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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