Threading bugs

BCS ao at pathlink.com
Tue Jun 26 13:48:54 PDT 2007


Reply to Tristam,

> So, I am sure that I must be missing something simple, that is causing
> my multi-threading code in D fail miserably. I have cut it down to the
> smallest code sample that exhibits the problem, and I would be
> grateful if someone could have a look and let me know why...
> 
> import std.thread;
> import std.stdio;
> class Main
> {
> this() {
> writefln("starting");
> Thread worker = new Thread(&workerMain);
> worker.start();
> }
> ~this() {
> writefln("ending");
> }
> int workerMain()
> {
> // -- disabled in case of deadlock in std.format, but never reached
> anyway
> //		writefln("In Thread");
> return 0;
> }
> Thread worker;
> }
> int main()
> {
> Main m = new Main();
> return 0;
> }

If I had to guess, I'd say that the program is exiting before the thread 
starts. But then I'm also guessing what the problem is.




More information about the Digitalmars-d-learn mailing list