Thread overview
Detecting premature end of spawned threads with std.concurrency
Sep 03, 2015
Matt Kline
Sep 04, 2015
Marc Schütz
Sep 04, 2015
Matt Kline
Sep 10, 2015
Ali Çehreli
September 03, 2015
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?
September 04, 2015
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".
September 04, 2015
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
September 04, 2015
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
September 10, 2015
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://dlang.org/phobos/std_concurrency.html#.LinkTerminated

  http://ddili.org/ders/d.en/concurrency.html#ix_concurrency.LinkTerminated

Ali