Threads not garbage collected ?

Alex via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 21 21:28:17 PST 2017


import core.thread;

class A
{
	Thread mThread;
	bool mStopped;
	
	this()
	{
		mThread = new Thread(&run);
		mThread.start();
	}
	
	void run()
	{
		while (!mStopped)
		{
			//do stuff
		}
	}
	~this()
	{
		mStopped = true;
		mThread.join();
	}
}



void main()
{
	auto a = new A;
	delete a;		//need this or the program hangs
}

In both gdc and dmd I need to use manually delete this object or 
the program is blocked after main. Is by design ?
It seems undesirable, as the thread can be many layers of 
encapsulation down, and they all need manual deletes.


More information about the Digitalmars-d mailing list