All Exams Test series for 1 year @ ₹349 only
Question

Which of the following are not shared by the threads of the same process?

(a) Stack

(b) Registers

(c) Address Space

(d) Message Queue

The correct answer is

(a) and (b)

Understanding Threads and Resource Sharing in a Process

In an operating system, a process is an instance of a program running. It's a complete execution environment with its own private memory space, code, data, and resources like open files and signals.

A thread, on the other hand, is a lightweight unit of execution within a process. A single process can have multiple threads running concurrently. These threads share certain resources belonging to the parent process but also have some resources that are unique to each thread.

Shared Resources Among Threads of the Same Process

When multiple threads belong to the same process, they share several key components of that process. These shared resources allow threads to cooperate and communicate more efficiently than separate processes.

  • Address Space: All threads within a process share the same virtual address space. This means they can access the same global variables, heap memory, and code section.
  • Code Section: The executable code of the program is shared among all its threads.
  • Data Section: Global variables and static variables are typically stored in the data section, which is shared by all threads.
  • Open Files: File descriptors for open files are generally shared among threads.
  • Signals and Signal Handlers: Signal handling is typically managed at the process level and shared by threads.

Resources NOT Shared by Threads of the Same Process

While threads share many resources, they also need their own independent components to manage their individual execution flow. These resources are unique to each thread.

  • Stack: Each thread has its own private stack. The stack is used to store local variables, function parameters, and return addresses for the function calls made by that specific thread. This is crucial because each thread executes functions independently.
  • Registers: Each thread has its own set of CPU registers (like the Program Counter (PC), Stack Pointer (SP), general-purpose registers). These registers hold the current state of the thread's execution context. When the operating system switches between threads, it saves and restores the register values for each thread.
  • Thread ID: Each thread is assigned a unique identifier (TID).
  • Thread-Local Storage (TLS): Some systems allow threads to have their own variables that are not shared, separate from global or local variables.

Analyzing the Given Options

Let's examine each option in the context of resources shared or not shared by threads within the same process:

  1. (a) Stack: As discussed, each thread has its own stack. Therefore, the stack is not shared.
  2. (b) Registers: Each thread has its own set of registers. Therefore, registers are not shared.
  3. (c) Address Space: Threads within the same process share the same address space. Therefore, the address space is shared.
  4. (d) Message Queue: Message queues are typically used for inter-process communication (IPC), but can also be used for communication between threads. If used for inter-thread communication, the message queue resource itself might be accessed by multiple threads, but the queue data structure would be managed as a shared resource within the process's address space. While its usage pattern might vary, it's fundamentally different from core per-thread components like stack and registers. The question asks what is *not* shared. Stack and Registers are definitively not shared at the individual thread level.

Based on the analysis, the Stack and Registers are the resources listed that are specifically not shared by the threads of the same process.

Conclusion on Resources Not Shared by Threads

The question asks which of the given resources are not shared by the threads of the same process. Our analysis confirms that the Stack and the Registers are unique to each thread and are not shared among them.

Shared vs. Non-Shared Resources in Threads
Resource Shared by Threads?
Stack No
Registers (CPU State) No
Address Space Yes
Code Section Yes
Data Section (Global/Static Variables) Yes
Open Files Yes
Signal Handlers Yes
Program Counter No (part of Registers)

Therefore, the resources that are not shared are Stack and Registers.

Revision Table: Key Thread Concepts

Revision: Key Thread Concepts Summary
Concept Description
Process An independent execution unit with its own address space and resources.
Thread A lightweight execution unit within a process, sharing process resources.
Thread Stack Memory area unique to each thread for local variables and function calls.
Thread Registers CPU state (PC, SP, etc.) unique to each thread.
Process Address Space The virtual memory range shared by all threads in a process.

Additional Information on Thread Management

Thread management is handled by the operating system's scheduler. When a context switch occurs between threads of the same process, it's often faster than a context switch between different processes because the shared resources like the address space don't need to be switched entirely. The OS only needs to save and restore the thread-specific context, mainly the registers and the stack pointer to the correct stack.

A Thread Control Block (TCB) is a data structure used by the operating system to store information about a specific thread. This information typically includes:

  • Thread ID
  • Register values (Program Counter, Stack Pointer, etc.)
  • Stack pointer to the thread's private stack
  • Thread state (running, ready, blocked, etc.)
  • Scheduling priority
  • Pointers to resources shared with other threads in the same process (like the process's Page Table Base Register).

Understanding which resources are shared and which are thread-specific is fundamental to understanding concurrent programming and operating system concepts.

Was this answer helpful?

Important Questions from Thread - Teaching

  1. If an operating system does not allow a child process to exist when the parent process has been terminated, this phenomenon is called as-

  2. Which of the following is not a state of a process in operating system?

  3. User level threads are threads that are visible to the programmer and are unknown to the kernel. The operating system kernel supports and manages kernel level threads. Three different types of models relate user and kernel level threads.

    Which of the following statements is/are true ?

    (a)

    (i) The Many - to - one model maps many user threads to one kernel thread

    (ii) The one - to - one model maps one user thread to one kernel thread

    (iii) The many - to - many model maps many user threads to smaller or equal kernel threads

    (b)

    (i) Many - to - one model maps many kernel threads to one user thread

    (ii) One - to - one model maps one kernel thread to one user thread

    (iii) Many - to- many model maps many kernel threads to smaller or equal user threads

  4. Match List-I with List-II

    List – I

    List – II

    (a) Disk

    (i) Thread

    (b) CPU

    (ii) Signal

    (c) Memory

    (iii) File System

    (d) Interrupt

    (iv) Virtual address

    Choose the correct option from those given below:
Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App