IAE Academy

GATE 2024 CS1 Q.24: solution and answer

GATE 2024 · CS1Q.24 · 1 mark · MSQ

Which of the following statements about threads is/are TRUE?

  1. (A)

    Threads can only be implemented in kernel space

  2. (B)

    Each thread has its own file descriptor table for open files

  3. (C)

    All the threads belonging to a process share a common stack

  4. (D)

    Threads belonging to a process are by default not protected from each other

See the question in the paper

Answer and solution

ANSWER

Only (D) is true: threads of one process share an address space and are not protected from each other by default.

Official answer: DSource: Official answer key, GATE 2024 CS1 (IISc Bengaluru)

  1. Recall what the threads of one process share and what each keeps private. Shared: code, global data, heap, open files (the file descriptor table), signal handlers and the address space. Private: program counter, registers, stack and thread ID.

  2. (A) False. Threads can be implemented in user space (user-level thread libraries, the many-to-one model) as well as in kernel space, or as a hybrid of the two. "Only in kernel space" is wrong.

  3. (B) False. The file descriptor table belongs to the process, so all its threads share it. A file opened by one thread can be used by the others.

  4. (C) False. Each thread needs its own stack for its call frames, local variables and return addresses. Only the heap and global data are shared.

  5. (D) True. All threads of a process run in one address space with no memory protection between them. One thread can read or overwrite another's data, and a stray write can corrupt the whole process. Any protection has to come from the programmer, for example with locks.

  6. Only (D) is correct.

KEY IDEA

Threads of a process share code, global data, heap and open files. Each thread has its own stack, registers and program counter. Because they share one address space, the operating system does not protect them from each other.

WATCH OUT FOR

Thinking each thread has its own file descriptor table (B), or that threads must live in the kernel (A). The table belongs to the process. Thread libraries can also run entirely in user space.

From the GATE 2024 CS1 paper. Every question of this paper · Download the full paper · All 9 Processes & threads questions, with notes

More Processes & threads questions