AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Easythreadsprocess

~60s

What threads do not share

Two threads belong to the same process. Which of these does each thread keep private?

Show the answer and the worked solution

Correct answer: D.

The stack and register set

Worked solution

  1. 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.
  2. The file descriptor table belongs to the process, so a file opened by one thread is visible to the others.
  3. 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.

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.

Question

Two threads belong to the same process. Which of these does each thread keep private?

Options

  1. The code section
  2. The global data section
  3. The list of open files
  4. The stack and register set
Show the answer and the worked solution

Correct answer: D. The stack and register set

Worked solution

  1. 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.
  2. The file descriptor table belongs to the process, so a file opened by one thread is visible to the others.
  3. 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.

All OS, DBMS & Networks questions · placement mock tests