Threading bugs
Tristam MacDonald
swiftcoder at gmail.com
Tue Jun 26 13:47:28 PDT 2007
And score 10 for forgetting to explain the problem :)
Anyway, this code sample should print "starting", star a thread that exits immediately, and finally print "ending" as the destructor is called at program termination.
Instead, it prints "starting" and then does nothing - or more precisely hogs the entirety of only one of my 2 cores - and never exits.
BTW, this is using gdc on a Mac (latest release of gdcmac), so could be a pthread specific problem perhaps?
Tristam MacDonald Wrote:
> 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;
> }
>
>
>
More information about the Digitalmars-d-learn
mailing list