Sorry, simple question but it is something that is always confused me when speaking about Operating Systems theory.
My book claims that reentrancy is made possible by using “the stack” – does this mean that there is one ‘stack’ and it is, somehow, shared among all routines, or does “the stack” refer to the abstract idea of a stack, and a stack is created and stored in main memory every time some subroutine is called ? (Assuming it is needed).
And what about the Stack Pointer in the CPU in this case ? How does that function, in either of these cases ?
Apologies for the vagueness of my description, the whole idea is just kind of shrouded in conflicting ideas for me !
This is platform specific (depends on used hardware and software).
Windows on x86/x64 has a memory for system stack ready for each thread. It is reused anytime you do a system call in that thread.
System is re-entrant when multiple independent processes or threads can call system routines at once. In this case each of those threads uses its own system stack. System stack (technically ring 0 stack) is independent from user mode (ring 3) stack.
I can also provide more information, just ask if you wish to know something more specific.
Stack pointer: