In: Computer Science
In a system with threads, is there normally one stack per thread or one stack per process? Explain.
Each thread has its own stack so it can utilize its own local variables, thread offer global variables which are essential for .data or .bss segments of linux executable.
Since threads share global variables that is, we use synchronization instruments like mutex when we need to get to/alter global variables in multi threaded application. Local variables are important for thread singular stack, so no need of any synchronization.
There is one stack for every thread whether you are utilizing real threads or simulated threads. A stack holds the call history of the thread and hence the factors of the calling schedules and the statement area from which they settled on the decision. At the point when you switch back to the thread, regardless of how it is executed, it can decide to "return" and should have a stack to actualize the return by reestablishing the past everyday practice at the point after the call. Obviously, on the off chance that you are simulating thread, at that point the substance of the "stack" might be not the same as the local stack oversaw by the OS and CPU, and deciphered dialects are allowed to make a stack dependent on pseudo-code instead of native machine guidelines. It is as yet a stack