Segmentation fault
Maxim Fomin
maxim at maxim-fomin.ru
Sun Dec 23 04:37:33 PST 2012
On Sunday, 23 December 2012 at 09:54:18 UTC, Shadow_exe wrote:
> 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();
> }
> }
>
> <skipped>
The problem is in heap corruption detected by valgrind in
gc.gc.mark() and some other functions. I remember similar issue
with using std.format functions in a loop. Increasing iterations
from 7000 up to 7500 lead to heap corruption.
The issue can be reduced to :
import std.stdio;
void main()
{
uint[] test;
for(uint y=0; y<1e6; ++y){
test ~= y;
}
writeln(test.length);
}
> If You after the launch of You have worked without errors,
> pozapuskayte several times.
He meant rerun multiple times here.
More information about the Digitalmars-d
mailing list