Hi Rand,

On Tue, May 21, 2013 at 05:56:52AM +0200, Rand Dow wrote:
> Each co-routine should have it's own separate stack. Best practices with
> stack management today have a sufficiently large stack that grows and then
> terminates in unmapped memory. If it is attempted to grow the stack too

OK. That's exactly how I implemented it.

> much, then the program gets a memory exception (SIGSEGV on systems that use

The stack pointer is decremented by the stack frame size (default 1 MB),
then the memory is accessed with normal operations.

> it). Think about a recursive routine with relatively large local data
> structures (stack-based). Such a routine could overwrite any amount of
> stack, finish, and then return with no errors. The current PicoLisp
> implementation sounds like, then, when a co-routine switch occurs, the
> switched to routine could find it's stack corrupted.

This doesn't happen usually. PicoLisp does runtime stack checks, so the
above would result in an stack overflow error (I say "usually", because
this is not 100% safe. You may call some 'native' code which does
unpredictable things to the stack, for example).

> And certainly operating system events could overwrite things deeper on the
> stack during a context switch.

As I said, these would use the system stack. And even if they would use
the user stack, there should be sufficient space. As I said, we have 1
MB per stack frame, and this can be easily extended with the 'stack'

Again, my problem is not to have a stack frame for each task, but having
stack frames BELOW the active stack pointer.

♪♫ Alex
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to