Standalone threads

Wolfgang Draxinger wdraxinger at darkstargames.de
Sun Feb 19 06:23:05 PST 2006


Lightoze wrote:

> class X : Thread {
> public this() {super(&(this.go));}
> public ~this() {printf("Thread deleted\n");}
> public int go() {printf("Thread started\n"); return 0;}
> }
> 
> int main(char[][] args) {
> while (true) {
> X x = new X;
> x.start();
> //            x.wait();
> }
> }
> 
> Code above works fine when "x.wait()" line is uncommented, but
> I dont want to wait X thread to end. If I comment this line
> huge memory leaks occur. Please suggest any ways to solve this
> problem, may be I need to add something at the end of go()
> method of thread?

You are aware, that above code will create threads endlessly if
you don't wait for the thread to terminate? That explains, why
the program sucks memory: Every thread has it's own stack and
instance of class X.

-- 
Wolfgang Draxinger




More information about the Digitalmars-d mailing list