[PD] What exactly is a "stack overflow" ?

Mathieu Bouchard matju at artengine.ca
Thu Dec 20 17:21:31 CET 2007


On Thu, 20 Dec 2007, Martin Peach wrote:

> a buffer is First In First Out, like a train in a tunnel.

Well, no. Perhaps some uses of the word "buffer" assume that, but most 
don't. "buffer" is a very vague word. If you want to say FIFO, you just 
say FIFO or you say queue.

> Pd processes messages in the order they are sent, it uses a buffer.

Oh no it doesn't. Pd's immediate message processing is LIFO ("depth 
first"); Pd's delayed message processing is FIFO ("breadth first"). Look 
at the execution order for a normal patch, then replace each connection by 
a delay with a pair of connections. You will observe a change from depth 
first to breadth first.

> I think the machine would not be useful with the stack on the hard drive, it 
> would be much too slow.

So what. It can do it anyway, and if it happens, it won't be any slower 
than if you had allocated the same arrays in heap instead, as the OS would 
also have to swap parts of the stack out, to make enough heap fit in.

> SIGSTKFLT is thrown by the cpu when the stack overflows, and registering a 
> handler amounts to modifying the interrupt table, so its the same thing.

So why didn't you just talk about SIGSTKFLT instead of going on about how 
ring 0 can do stuff a user mode process can't?

> Well obviously you're supposed to do it before the stack is too big.

If the stack is not too big, then you don't get a STKFLT.

> If as you say the OS starts out with no stack and waits for trouble, it 
> would have the same problem. I would have thought that a stack overflow 
> requires a restart, unless the exception kicks in before the absolute 
> end of the stack.

I hope so. If it does, then surely it gives at least a full 4k extra (you 
can't wait for non-4k boundaries unless you're in very slow debug mode 
like what valgrind does).

  _ _ __ ___ _____ ________ _____________ _____________________ ...
| Mathieu Bouchard - tél:+1.514.383.3801, Montréal QC Canada


More information about the Pd-list mailing list