Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Reviewer: Threads and Multithreading What is a Thread? Definition: A thread is the basic unit of CPU utilization. Components of a Thread: o Thread ID o Program counter o Set of registers o Stack Thread Attributes: o Thr...

Reviewer: Threads and Multithreading What is a Thread? Definition: A thread is the basic unit of CPU utilization. Components of a Thread: o Thread ID o Program counter o Set of registers o Stack Thread Attributes: o Thread execution state o Saved thread context (when not running) o Static storage for local variables o Access to the memory and resources of the process o Execution stack Thread Characteristics Shared Resources: Threads share the same code section, data section, and operating system (OS) resources within the same process. Multitasking: Threads allow a process to perform multiple tasks simultaneously. Thread States: Running: The thread is currently being executed. Ready: The thread is waiting to be assigned to a processor. Blocked: The thread is waiting for some event to occur before it can proceed. Thread Operations: 1. Spawn: When a new process is created, a thread is also formed. 2. Block: The thread waits for a specific event and saves its current state. 3. Unblock: Moves the thread back to the ready state after the event has occurred. 4. Finish: When the thread completes its execution, it deallocates its resources. Types of Threads: User-Level Threads: o Managed by the application. o OS is unaware of their existence. o Faster thread switching, no need for kernel mode privileges. o Examples: Single-process applications, where the thread scheduling is controlled by the application. Kernel-Level Threads: o Managed by the OS kernel. o The kernel maintains information about each thread. o Supports multiple processors and can schedule multiple threads on different processors. o Examples: Multithreaded applications running on multicore systems. Combined User-Level and Kernel-Level Threads: o Combines the benefits of both user-level and kernel-level threads. o Example: Solaris operating system. Multithreading: Definition: Multithreading is the ability of an operating system to support multiple threads within a single process. Benefits of Multithreading: 1. Responsiveness: Threads allow parts of an application to remain responsive even if other parts are blocked. 2. Resource Sharing: Threads within the same process share the same memory and resources. 3. Economical: Thread creation requires less memory and CPU resources compared to process creation. 4. Scalability: Threads can run in parallel on multiprocessor systems, improving performance. Examples of Multithreading: Web browsers: Downloading data while rendering the webpage. Word processors: Checking spelling while responding to user input. Photo applications: Generating thumbnails while loading images. Thread Libraries: Provide APIs for creating and managing threads. Functions include: o Creating and destroying threads o Passing messages between threads o Scheduling thread execution o Saving and restoring thread context This reviewer focuses on the fundamental concepts of threads, their types, and the significance of multithreading in improving application performance.

Use Quizgecko on...
Browser
Browser