Magic infinite loop inside foreach

Ali Çehreli acehreli at yahoo.com
Thu Jan 30 15:24:42 PST 2014


On 01/30/2014 03:08 PM, MrSmith wrote:

 > On Thursday, 30 January 2014 at 22:56:46 UTC, MrSmith wrote:
 >> I have some function which does some matrix calculations and prints
 >> them. It is actually calculationg determinant of the matrix and i need
 >> to call those functions several times in the loop, until i get the
 >> final result. Here is the code.
 >>
 >> void solveAndPrint(T : CoeffMatrix!(ElementType, ElementType),
 >> ElementType)(T _matrix)
 >> {
 >>     auto matrix = _matrix;
 >>     TempMatrix!ElementType temp;
 >>
 >>     foreach(_; 0..3) //3 is just for debug
 >>     {
 >>         writeln(matrix);
 >>         temp = makeTemp(matrix);
 >>
 >>         writeln(temp);
 >>         matrix = solveTemp(temp);

Does that mutate temp in any way? If so, probably the change is 
affecting how solveTemp() works the next time.

 >>
 >>         writeln("done1");
 >>         stdout.flush();
 >>     }
 >>     writeln("done2");
 >>     stdout.flush();
 >> }
 >>
 >> The problem is that after 'done1' is printed it is running infinitely
 >> consuming all the processor just like if has infinite loop inside.
 >> done2 is never printed.
 >
 > Somehow if i comment out
 > //matrix = solveTemp(temp);
 > it works, but this method works fine, and after it done1 is printed.
 > Strange.

Ali



More information about the Digitalmars-d-learn mailing list