Thread
In computer science, a thread is a lightweight process that can execute concurrently with other threads within the same process. Threads share the same memory space and system resources, but each thread has its own execution stack and program counter. Multithreading refers to the ability of a program to create multiple threads that can execute simultaneously. Multithreading provides several benefits over single-threaded programs, such as improved performance and responsiveness.
Benefits of Multithreading
Multithreading offers several benefits over single-threaded programs:
Improved Performance
Multithreading can improve the performance of a program by allowing multiple tasks to execute concurrently. For example, a program that performs both input/output operations and computations can use separate threads for each task, allowing them to execute simultaneously and reducing overall execution time.
Enhanced Responsiveness
Multithreading can improve the responsiveness of a program by allowing it to continue executing while waiting for a blocking operation to complete. For example, a graphical user interface can use a separate thread to handle user input, allowing the program to remain responsive while waiting for user actions.
Resource Sharing
Threads share the same memory space and system resources, allowing them to communicate and share data efficiently. This can simplify programming and reduce memory usage.
Simplicity
Multithreading can simplify programming by allowing complex tasks to be split into smaller, more manageable pieces. Each thread can focus on a specific task, making the program easier to understand and debug.
Resources Used When a Thread is Created
When a thread is created, several resources are used, including:
Memory
Each thread has its own stack and execution context, which requires memory. The amount of memory used by a thread depends on the size of its stack and the data it stores.
CPU Time
Each thread requires CPU time to execute. When multiple threads are running simultaneously, the operating system allocates CPU time to each thread based on its priority and the amount of work to be done.
Synchronization Objects
Threads that share data or resources must use synchronization objects, such as semaphores or mutexes, to avoid conflicts and ensure correctness. These objects require system resources, such as memory and CPU time.
Overhead
Creating and managing threads requires additional overhead, such as context switching and scheduling, which can reduce performance.
OS-2022
Q-1.
(a) Write are the functions of operating systems? write a note on multi programmed operating systems ?
(b) Distinguish between client server and peer to peer model of distributed systems .
Q-2.
(b) What is meant by Storage Structure? Discuss Storage Hierarchy.
Q-3.
(a) What are the criteria for evaluating the CPU scheduling algorithms? Why do we need it?
Q-4.
(a) What is synchronization? Explain how semaphores can be used to deal with n-process critical problem.
Q-5.
Q-6.
(b) What are the disadvantages of single contiguous memory allocation? Explain.
Q-7.
(a) Briefly explain about single-level, two-level and three Structured directories.
(b) What is disk scheduling? Explain the C-SCAN scheduling by giving an example.
Q-8.
(b) UNIX file system.