Threads of a process share

2017

Threads of a process share

  1. A.

    global variables but not heap

  2. B.

    heap but not global variables

  3. C.

    neither global variables nor heap

  4. 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.

Explore the full course: Gate Guidance By Sanchit Sir