Bug in phobos Thread module?

Regan Heath regan at netmail.co.nz
Sun May 13 08:21:08 PDT 2007


Thought you might want some test code to demonstrate the problem.

# import std.thread, std.c.time, std.c.windows.windows;
# 
# class Threader : Thread {
# 	int id;
# 	
# 	this(int _id) { id = _id; printf("thread %d\n",id); }
# 	~this() {printf("deconstructing %d\n",id);}
# 	
# 	int run() {
# 		msleep(1000);
# 		CloseHandle(hdl);
# 		delete this;
# 		return 0;
# 	}
# }
# 
# void main() {
# 	for(uint i = 0; i < 4000; i++) {
# 		(new Threader(i)).start;
# 		msleep(50);
# 	}
# }

If you remove the call to CloseHandle and configure task manager to show handles and threads you should see the number of threads at a constant, around 17, and the number of handles steadily climbing.

The addition of CloseHandle causes the number of handles to remain steady also, at approximately 2x the number of threads.

The correct location for the call to CloseHandle, I believe, is at the end of threadstart, as shown in my other reply.

Can someone run this same code on linux (without CloseHandle etc) and use 'top' or similar to watch the thread and handle counts, I suspect no fix is required for linux but I may be mistaken.



More information about the Digitalmars-d mailing list