Clearing the Stack?
CannibalRobotics
Posts: 535
So I've got this huge program that runs great for a matter of several hours across 7 cogs. It uses allot of recursion and infinite loops in three of the cogs. The others are running FullDuplexSerial and the Floating point routines.
At some point, variables in the Top object (and possibly others) start getting set to the wrong value and it slowly degrades from there. If I let it run long enough, occasionally it will start getting the right answers again. Other times it will keep running but the calculations are just wrong.
Interestingly enough, I can identify the source of the wrong values. They start coming from variables 4 or 5 long's away from where they are supposed to be in the VAR section.
I have tried all sorts of stack allocations across all of the cogs, trying to minimize and maximize, nothing seems to help.
I've tried some of the code suggestions regarding measuring stack depth but when I write all of the 'same character' into the stack location of one cog, the whole program locks up.
My experience tells me I'm missing something obvious but I've just looked at it too long.
Short of building in hourly resets - is there any way to get control of this?
At some point, variables in the Top object (and possibly others) start getting set to the wrong value and it slowly degrades from there. If I let it run long enough, occasionally it will start getting the right answers again. Other times it will keep running but the calculations are just wrong.
Interestingly enough, I can identify the source of the wrong values. They start coming from variables 4 or 5 long's away from where they are supposed to be in the VAR section.
I have tried all sorts of stack allocations across all of the cogs, trying to minimize and maximize, nothing seems to help.
I've tried some of the code suggestions regarding measuring stack depth but when I write all of the 'same character' into the stack location of one cog, the whole program locks up.
My experience tells me I'm missing something obvious but I've just looked at it too long.
Short of building in hourly resets - is there any way to get control of this?
Comments
Is some data walking on top of something else? Functionally, your code seems to work but time (memory leaks) or data (something not big enough) throws your program into fits. Something defined incorrectly, buffer too small, time sensitive...good until 9:59 but at 10:00 it goes bad?
Without specifics of the program, it's going to be pretty hard to help out more than with just generic thoughts.
Rick.
To get the stack pointer, you could reference @RESULT or, if there are local variables, get the address of the last local variable.
Thought about posting the code but it's massive.
I can't really nail down a time or an event. I'm wondering if the recursive nature of it is continually grabbing more memory and it eventually eats into the variable area?
Dave
No that's not it, I was thinking in terms of the address not the value.
Any Value is initialized before I use it.
Jim