Bug 11309 – std.concurrency: OwnerTerminated message doesn't work

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-20T18:44:00Z
Last change time
2013-11-13T16:08:31Z
Assigned to
code
Creator
mk

Comments

Comment #0 by mk — 2013-10-20T18:44:09Z
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.
Comment #1 by bugzilla — 2013-10-22T14:26:29Z
Did this work on earlier versions of dmd?
Comment #2 by andrej.mitrovich — 2013-10-22T14:29:29Z
It works in 2.063.2, but gets stuck in git-head. I'm on Win7 x86.
Comment #3 by mk — 2013-10-22T16:31:28Z
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); }
Comment #4 by mk — 2013-10-23T06:33:31Z
Comment #5 by code — 2013-10-25T08:39:34Z
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.
Comment #6 by bugzilla — 2013-10-26T13:27:47Z
What's the solution here? Revert the pull?
Comment #7 by code — 2013-10-29T07:27:31Z
(In reply to comment #6) > What's the solution here? Revert the pull? Refixing bug 10976 which was caused by bug 11378.
Comment #8 by code — 2013-10-29T12:04:58Z
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.
Comment #9 by github-bugzilla — 2013-10-30T00:13:17Z
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
Comment #10 by mk — 2013-11-11T04:29:48Z
*** Issue 11492 has been marked as a duplicate of this issue. ***
Comment #11 by mk — 2013-11-11T04:32:15Z
Reopening, as it seems to still crash on Linux x86_64.
Comment #12 by code — 2013-11-11T04:53:37Z
(In reply to comment #11) > Reopening, as it seems to still crash on Linux x86_64. Which dmd version are you using?
Comment #13 by mk — 2013-11-11T05:00:16Z
(In reply to comment #12) > Which dmd version are you using? See bug 11492. I've tried on dpaste, which seems to be using 2.064.2.
Comment #14 by atila.neves — 2013-11-11T05:07:47Z
(In reply to comment #8) > 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. Maybe, but this used to work in the previous version and is a blocking bug for me.
Comment #15 by atila.neves — 2013-11-11T05:09:10Z
(In reply to comment #12) > (In reply to comment #11) > > Reopening, as it seems to still crash on Linux x86_64. > > Which dmd version are you using? I used both the 2.064.2 64-bit Linux binary from the zip file on dlang.org and the one from the official Arch repository (also 2.064.2). They both produce an executable that crashes.