GATE / CS ARCHIVE

SIMILAR QUESTIONS / OPERATING SYSTEMS

Identify thread private and process shared state

4 questions solved the same way, newest first. Back to Operating Systems

How these are solved

Distinguish common address-space/heap/global state from each thread stack, PC and registers. 2023 asks which values need saving during a same-process thread switch, using the same state classification.

1 mark · MSQ
Report issue

Processes, Threads & System Calls

Question 22, GATE 2023: During a switch between two threads of the same process, which state needs saving? A page-table base register; B stack pointer; C program counter; D general-purpose registers. Select all applicable options.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: B, C, D

Threads in one process share the same virtual address space, so the page-table base normally need not change. Their stacks, instruction positions, and working register values differ, requiring preservation of stack pointer, program counter, and general-purpose registers. Thus B, C, D in the usual same-process thread model.

Teaching detail. A thread must later resume at its own instruction and restore the register values on which that computation depends. It also needs its own stack pointer because function frames and local storage belong to that thread's call chain. Threads in one process ordinarily share the page tables, so changing only the thread does not require switching the address-space root. Real implementations may save additional architecture-specific state, but that does not alter which of the four listed items are logically thread-specific in the stated model.

Original paper, page 20 · Answer key

1 mark · MCQ
Report issue

Processes, Threads & System Calls

Question 18, GATE 2017: Threads of one process share: A globals but not heap; B heap but not globals; C neither globals nor heap; D both globals and heap.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

1. Threads are separate execution streams inside the same process address space. Globals live in that shared address space.

2. Heap allocations also belong to the process address space; one thread can pass an allocated object’s address to another. Sharing does not itself make unsynchronized updates safe.

3. Each thread instead has its own execution state, such as registers and program counter, and normally its own stack. Hence both heap and globals are shared, D.

Original paper, page 10 · Answer key

1 mark · MCQ
Report issue

Processes, Threads & System Calls

Question 7, GATE 2017: Which are shared by all threads of one process? I:program counter. II:stack. III:address space. IV:registers. A:I and II. B:III only. C:IV only. D:III and IV.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Threads belong to one process and operate in its common virtual address space, including code, global data and heap. Thus III is shared.

2. Each thread may be executing a different instruction, so it needs its own program counter and saved register values. Sharing one program counter or register context would prevent independent execution.

3. Each thread also needs its own call stack for local variables, return addresses and nested calls. Although another thread may access that stack through an address in the shared memory, the execution stack is still distinct. Hence only III is correct, B.

Original paper, page 4 · Answer key

1 mark · MCQ
Report issue

Per-thread versus per-process state

Processes, Threads & System Calls

Question 16, GATE 2011: Threads are called lightweight processes because the OS maintains smaller structures for a thread than a process. Which statement is TRUE?

(A) Per thread, the OS maintains only CPU register state
(B) The OS does not maintain a separate stack for each thread
(C) Per thread, the OS does not maintain virtual-memory state
(D) Per thread, the OS maintains only scheduling and accounting information
Tap to enlarge
Your answer
Answer & solution

Official answer: C

Threads of one process share its virtual address space, so virtual-memory mappings are maintained at process level rather than separately for each thread. Each thread still needs its own register context, stack and scheduling information. Therefore C.

Independent execution requires each thread to remember its own instruction pointer and registers, and its own stack holds function calls and local execution state. The scheduler also tracks the thread's run/block status. Those facts refute A, B and D: none of the single listed items is the whole thread context, and stacks are not omitted. Virtual-memory mappings, however, describe the shared process address space, which is why C identifies the saving.

Original paper, page 4 · Answer key