Q42: Threads and stack

Question #42: Do threads need different stack?

  1. Yes, they have different execution tracks, hence they need different stacks.
  2. Sometimes they need.
  3. No, they have common code segment, hence they don’t need different stacks.
  4. None of the above.

 

Solution:

Stack grows and shrinks as and when threads take different paths. And, multiple threads in same or different processes can take different execution paths, hence a dedicated stack is needed for all of the threads to execute. Therefore, the correct answer is option 1.