What threads do not share — Aptitude Question
What threads do not share: Two threads belong to the same process. Which of these does each thread keep private? Answer and worked solution on CodeKairo.
- Topic: OS, DBMS & Networks
- Section: Programming MCQs
- Difficulty: Easy
- Time target: 60 seconds
Question
Two threads belong to the same process. Which of these does each thread keep private?
Options
- The code section
- The global data section
- The list of open files
- The stack and register set
Show the answer and the worked solution
Correct answer: D. The stack and register set
Worked solution
- Threads of one process share its address space, so the code and the global data are common to all of them — which is why they need locks around shared variables.
- The file descriptor table belongs to the process, so a file opened by one thread is visible to the others.
- Each thread runs its own chain of function calls and sits at its own instruction. The stack and register set are therefore private to every thread.
Answer: The stack and register set.
The idea
The dividing line is simple: anything describing where a thread is in the program is private, and anything describing what the program owns is shared.
Shortcut. Two threads can be inside different functions at once, so each needs its own return addresses and program counter, the stack and registers; the rest is process-wide.
Common trap. "The global data section" feels per-thread because each thread can change globals, but they are shared, which is exactly why races happen.