www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Detecting premature end of spawned threads with std.concurrency

reply "Matt Kline" <matt bitbashing.io> writes:
TDPL suggests that calls to std.concurrency.send will fail with 
an "OwnedTerminated" or "OwnedFailed" exception if the 
destination thread has exited, but neither the docs nor the 
current Phobos implementation make any mention of such 
exceptions. Thinking the information was just outdated, I 
searched the Git history of Phobos for such types, but found 
nothing.

What are current best practices for determining if a child thread 
has died? And should these types be added to TDPL errata?
Sep 03 2015
next sibling parent reply "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Thursday, 3 September 2015 at 21:20:59 UTC, Matt Kline wrote:
 TDPL suggests that calls to std.concurrency.send will fail with 
 an "OwnedTerminated" or "OwnedFailed" exception if the 
 destination thread has exited, but neither the docs nor the 
 current Phobos implementation make any mention of such 
 exceptions. Thinking the information was just outdated, I 
 searched the Git history of Phobos for such types, but found 
 nothing.

 What are current best practices for determining if a child 
 thread has died? And should these types be added to TDPL errata?
They're called `OwnerTerminated` and `OwnerFailed` with an "r".
Sep 04 2015
parent "Matt Kline" <matt bitbashing.io> writes:
On Friday, 4 September 2015 at 08:33:08 UTC, Marc Schütz wrote:
 They're called `OwnerTerminated` and `OwnerFailed` with an "r".
No, that's received by the child if the owning thread exits. I'm talking about the "parent" thread attempting to send to a child thread that has exited. Relevant passage in TDPL: https://books.google.com/books?id=bn7GNq6fiIUC&pg=PT602
Sep 04 2015
prev sibling next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 9/3/15 5:20 PM, Matt Kline wrote:
 TDPL suggests that calls to std.concurrency.send will fail with an
 "OwnedTerminated" or "OwnedFailed" exception if the destination thread
 has exited, but neither the docs nor the current Phobos implementation
 make any mention of such exceptions. Thinking the information was just
 outdated, I searched the Git history of Phobos for such types, but found
 nothing.

 What are current best practices for determining if a child thread has
 died? And should these types be added to TDPL errata?
It seems this is not handled. Looking here: https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L506 spawn creates the thread, then calls the function, but never sets a flag indicating when the thread is done. This could be added quite easily by adding a scope(exit) to the executed function (exec). It would not happen if the thread is terminated abnormally, but any thrown exception should trigger the flag. I'll note that the MessageBox class has a close() method that seems like it could be called. Anyone want to make a PR? And no, I'm not going to :) -Steve
Sep 04 2015
prev sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 09/03/2015 02:20 PM, Matt Kline wrote:
 neither the docs nor the current Phobos implementation
 make any mention of such exceptions.
There is LinkTerminated but you must use spawnLinked(): http://ddili.org/ders/d.en/concurrency.html#ix_concurrency.LinkTerminated Ali
Sep 10 2015