On 07/20/2013 12:34 PM, Alex Horvat wrote:

> If I use core.thread.Thread to create a new thread associated to a
> function like this:
>
> Thread testThread = new Thread(&DoSomething);
>
> Will the testThread dispose of itself after DoSomething() completes, or
> do I need to join/destroy/somethingelse testThread?

When the execution of the thread finishes, you will end up with a completed thread:

import std.stdio;
import core.thread;

void DoSomething()
{
    writeln("Doing something...");
}

void main()
{
    auto thread = new Thread(&DoSomething);
    thread.start();

    thread_joinAll();

    assert(!thread.isRunning);    // <-- Not running
}

You do not need to do anything with the object. In fact, the documentation says that you shouldn't delete it: "instances of this class should never be explicitly deleted". ('delete' is gone, so it should mean that you shouldn't destroy() it.)

Ali

Reply via email to