Re: Who uses tasks?
- Posted by mattlewis (admin) Sep 10, 2009
- 1101 views
I have no idea how tasks code works but if you want to watch the stack pointer position why don't you read the stack pointer register and compare it with a saved value of itself.
Does-it make any sense in this context?
Not really. Or maybe. It's complicated. Translated routines are native C routines, meaning that they manipulate the stack in a 'normal' way, as opposed to interpreted code, which actually uses the heap for the equivalent of stack space. Tasks are a way for a euphoria program to cooperatively multitask among its routines.
So we are allowed to suspend one routine, and start/resume execution of another. So the way it works is that you start with a 'normal' stack, prior to creating any tasks. When you start creating tasks, the task management stuff from the runtime library starts slicing up the stack for your various tasks to use.
When a task is called, the stack pointer is changed to wherever that task's stack space is. When it yields, the stack pointer goes back so that the back end task management stuff can figure out which task should run next.
However, if we can't even be sure that the stack won't get corrupted, we certainly can't go back and use it that way.
Matt