Ex 05
Ex 05
14 Threads
- The traditionel process assums a single thread of execution.
- Morden openrating systems extend the process model to support multithreading.
- To support threads , the Process Control Block is expanded to include information for each thread.
4.1 Overview
- Threads are the smallest unit of CPU untilization , consist of a thread ID, a program counter, a
register set , a stack.Thread
- Thread within the same process share the process's code section, data section, and openratings
system resources.
Benefits of multithreadeding:
- Responsiveness: multithreading allows applications to remain responsive.For example
, a user interface can stay interactive while background thread handles a time-consuming task.
- Resource Sharing : Threads share memory and resources of their parent process by default.
- Economy : Creating and managing theads is faster than creating and managing processes.
- Scalability : Multithreading can improve the performance of applications that are designed to
handle multiple tasks concurrently.
Application of Multithreading:
- Web servers: handling multiple client requests concurrently.
- Database servers: processing multiple queries concurrently.
- Real-time systems: handling multiple events concurrently.
- Multimedia applications: playing multiple audio and video streams concurrently.
Single-core vs Multicore:
- On a single-core system , theads are interleaved over time.
- On a multicore system , threads can run in parallel on separate cores.
Prgramming Challenges: Designing and programming for muticore systems present several challenges
- Indentifying Tasks:break applications into separate, concurrent tasks that can run independently on
different cores.
- Balance:Ensure tasks perform equal work equal value justify the use of addtional cores.
- Data Splitting: Divide data accessed by tasks to run on separate cores.
- Data Denpendency: Synchronize tasks when one depends on the data from another.
- Testing and Debugging : Concurrent programs are harder to test and debug due to multiple
execution paths.
4.3Multithreading Models: MultiThreading can implemented at to levels: user threads and kernel
threads