Do threads 'end' themselves using core.thread?

Alex Horvat alexh at gmail.com
Mon Jul 22 08:32:54 PDT 2013


On Sunday, 21 July 2013 at 15:30:06 UTC, Ali Çehreli wrote:
> On 07/20/2013 09:43 PM, Ali Çehreli wrote:
>
> > When the parent thread terminates the child processes
> terminate as well.
>
> I am wrong there: What I said above is true for the main 
> program thread. When the main program terminates, its threads 
> are terminated as well.
>
> Otherwise, a child can continue running even though its parent 
> (owner) has terminated. This is evidenced by the fact that 
> std.concurrency has an exception named OwnerTerminated, useful 
> for the child.
>
> Ali

Thanks again, but I feel I need to give more details - what I 
really want to know is if what I'm doing will cause a memory leak 
by leaving a child thread going - the parent thread won't exit 
until the program is closed.

The program is loading a video onto a gtkOverlay widget, then 
overlaying a label to display the name of the video. Once the 
label is displayed a thread is created, which waits 3 seconds 
then hides the label. After creating the thread the parent thread 
has nothing more to do with it.

I've included a bit more code below:

private Label _lblTitle;

public void LoadVideo()
{
   //Setting up video here....

   _lblTitle.setText("example");
   _lblTitle.show();

   //Spawn a new thread to hide the title
   Thread TitleHider = new Thread(&DelayedHideTitle);
   TitleHider.start();

   //Keep going on main thread...
}

private void DelayedHideTitle()
{
   Thread.sleep(dur!"seconds"(3));
   _lblTitle.hide();
}

DelayedHideTitle() is the entire contents of the child thread, 
after the method finishes does the thread TitleHider dispose of 
itself?


More information about the Digitalmars-d-learn mailing list