Segmentation fault

Shadow_exe shadow_exe at ukr.net
Sun Dec 23 01:54:17 PST 2012


There is an error, which I can not solve, because I can't 
understand why it happens.
If it's not an error, correct me please!

Code:
module main;

import core.thread;
import std.stdio;
import core.memory;

class DerivedThread : Thread {
     this(uint index){
         this._index = index;
         super( &run );
     }

     private uint _index;


     private {
         void run(){
                 writeln("run ", _index);
                 uint[] test11;
                 for(uint y=0; y<1e6; ++y){
                     test11 ~= y;
                 }
                 writeln("done ", _index);
         }
     }
}

void main(string[] argv)
{
     for(uint i=0; i<10; ++i){
         (new DerivedThread(i)).start();
     }
}

compil:
dmd ./main.d -debug -profile -w -v -g -cov -gs
// version   v2.060

Compiles without a single warning, well, that's understandable, 
code there simple...
But when I run! Sometimes displays like this:
./main
run 3
run 1
run 0
run 2
run 4
run 5
run 6
run 7
run 8
run 9
done 0
done 8
done 3
done 1
done 2
done 4
done 6
done 5
done 7
done 9
// And everything is fine!
But sometimes:
./main
Segmentation fault
Or is it:
./main
run 0
Segmentation fault

If You after the launch of You have worked without errors, 
pozapuskayte several times.
What am I doing wrong? Help.


More information about the Digitalmars-d mailing list