Do threads 'end' themselves using core.thread?

Sean Kelly sean at invisibleduck.org
Mon Jul 22 11:22:05 PDT 2013


On Jul 22, 2013, at 10:25 AM, Alex Horvat <alexh at gmail.com> wrote:

> On Monday, 22 July 2013 at 16:58:00 UTC, Sean Kelly wrote:
>> On Jul 22, 2013, at 9:45 AM, "Alex Horvat" <alexh at gmail.com> wrote:
>> 
>>>> ....
>>>> When a detached thread terminates, its resources are auto- matically released back to the system:"
>>> Sounds like I can call Thread.getThis().thread_detachThis() from within DelayedHideTitle() and that will make the thread detached and therefore it will destroy itself properly.
>> 
>> Only call thread_detachThis() if you initialized the thread object via thread_attachThis().  Otherwise just discard the reference and let it clean itself up.  The reason for the "do not delete" restriction is because the thread objects are tracked internally by the GC, and they must remain in a correct state until the GC has recognized that they have terminated.
> 
> Thanks, sounds like I can just do this and the thread will clean itself up:
> 
> Thread TitleHider = new Thread(&DelayedHideTitle);
> TitleHider.start();
> TitleHider = null;

Yep.


More information about the Digitalmars-d-learn mailing list