Threads of a process share
2017
Threads of a process share
- A.
global variables but not heap
- B.
heap but not global variables
- C.
neither global variables nor heap
- D.
both heap and global variables
Attempted by 359 students.
Show answer & explanation
Correct answer: D
Answer: both heap and global variables
Explanation: Threads created within the same process share the process-wide address space. That means the heap and global/static variables are common to all threads and any thread can read or modify data in those regions.
Commonly shared resources include:
Heap memory
Global/static variables
Code/text segment and other process-wide mappings (e.g., memory-mapped files)
Open file descriptors and other kernel resources associated with the process
Per-thread private resources (not shared):
Each thread's stack
CPU context (registers, including the program counter)
Thread-local storage (TLS)
Practical note: Because the heap and globals are shared, concurrent access must be synchronized (for example, using mutexes) to avoid race conditions.
A video solution is available for this question — log in and enroll to watch it.