Re: Who uses tasks?
- Posted by mattlewis (admin) Sep 10, 2009
- 1165 views
I have feeling that the OS may be doing something with the stack, messing up the stuff that euphoria leaves there. I think the translated task stuff does things it's probably not supposed to be doing. We may need to rewrite the task backend for translated code.
Did this always fail in translated code or just in 4.0?
I'm not sure when it started failing. I believe that it used to work. There hasn't been much that's changed in be_task.c. There were some changes needed for interpreted tasks when built with gcc, due to the way were were using a variable on the stack after we should have.
Again, that used to work, but either gcc or the kernel, or something changed to invalidate the way we were doing stuff. I don't know enough to say definitively, but the way that translated tasks are handled really seems hacky and dangerous to me.
Basically, we rely on the memory above the current stack pointer to stay the same, and we write some guard values in there. The space gets chopped up for use by the various tasks, and we watch for overflowing the boundaries that we've set.
Basically, when one of our guard values changes, we assume that a stack overflow has occurred by one of the tasks. This is what happens, except that it happens immediately, and isn't because one of our stacks went too deep in its call stack. So, since I don't believe that anything we actively did changed the value, I assume that it's something that the OS is doingand why shouldn't it, we never allocated that memory via malloc or the stack.
There is an attempt made to allocate more stack space by recursively calling a function whose purpose is solely to take up stack space (I think there is a way in windows to ask for lots of stack space ahead of time). I think we came across something that happened to work, but certainly wasn't guaranteed to work, and it no longer does.
That's why I've proposed rewriting it using threads so that we can allow the OS / thread library to manage our stacks, etc, and we can use mutexes or something to keep only a single task running at a time.
Matt