views:

59

answers:

1

Hi there,

I did a search but couldn't find anything. I was reading a paper that mentions thread sharing stack locations.... I wonder how and why'd that be needed. Any examples would be highly appreciated.

Many thanks.

+1  A: 

If you declare a variable on the stack and pass it's address to another thread, you are essentially sharing a stack location. Is that what the paper described?

Or was the paper referring to OS support such that the threads using the same stack to keep the EIP/SP etc.? Seems like a problem waiting to happen for me. I guess you could do that to make sure that stack space is not wasted for each thread when you know the constraints of your code, but seems like an overkill.

Alienfluid
It does not say anything in detail and personally I thought stack was supposed to be private to each thread, but does anyone do it in practice? I mean sharing stack locations?
Achilles
All threads in the process have access to the entire process virtual address space - so no location is really private "per stack". The system tries to emulate a private space per thread by storing the EIP/SP and local variables for each stack frame in different locations (the stack space is initialized at thread create) and provides facilities like TLS (thread local storage), but in the end its all just an illusion anyway. A cleverly crafted program can certainly use the same stack location to store shared data. In Windows, you can specify the stack size on thread create.
Alienfluid