John E
March 1st, 2004, 03:19 AM
I never really thought of this before but what happens to a program's stack pointer after it launches multiple threads?
Obviously the threads are time-sliced so they aren't literally happening simultaneously - but there's nothing to stop a function being called in thread 'B' while another function in thread 'A' is still executing. With a single stack this would presumably push new variables onto the stack which thread 'A' doesn't know about. How is this resolved? Does the OS take care of the stack pointer while switching between threads or does each thread get its own stack space :confused:
Obviously the threads are time-sliced so they aren't literally happening simultaneously - but there's nothing to stop a function being called in thread 'B' while another function in thread 'A' is still executing. With a single stack this would presumably push new variables onto the stack which thread 'A' doesn't know about. How is this resolved? Does the OS take care of the stack pointer while switching between threads or does each thread get its own stack space :confused: