How Stop Worker Thread if Owner Thread is Finished?

Marcone marcone at email.com
Tue Oct 27 13:56:04 UTC 2020


On Tuesday, 27 October 2020 at 12:16:01 UTC, Rene Zwanenburg 
wrote:
> On Tuesday, 27 October 2020 at 11:36:42 UTC, Marcone wrote:
>> I want to use isDaemon to automatic stop worker thread if 
>> ownner thread is finished
>
> Terminating threads without properly unwinding the stack is 
> generally a very bad idea. Most importantly the destructors of 
> stucts on the stack won't run which can cause problems like 
> locks not being released.
>
> This isn't specific to D either. For example Raymond Chen 
> writes about the TerminateThread function in Windows here:
> https://devblogs.microsoft.com/oldnewthing/20150814-00/?p=91811
>
> You should signal the thread somehow that it's time to stop 
> working

isDaemon: A daemon thread is automatically terminated when all 
non-daemon threads have terminated.


More information about the Digitalmars-d-learn mailing list