On 07/22/2013 08:32 AM, Alex Horvat wrote:
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?
Unfortunately, I don't know enough to answer these questions. :(
pthread_create man page says: "Only when a terminated joinable thread
has been joined are the last of its resources released back to the
system. When a detached thread terminates, its resources are auto-
matically released back to the system:"
Apparently, it is possible to detach from a thread or even to start it
in the detached state to begin with: "By default, a new thread is
created in a joinable state, unless attr was set to create the thread in
a detached state (using pthread_attr_setdetachstate(3))." But
core.thread doesn't seem to provide either of those.
Ali