Module 2
Module 2
Multi-Threaded Architectures
Definition:
• Multi-threaded architectures involve multiple threads of execution
within a single process, allowing for concurrent execution of code.
Threads share the same memory space but execute different parts
of the program simultaneously.
Characteristics:
• Shared Memory: Threads within the same process share the same
address space, which allows for efficient communication and data
sharing between threads.
• Context Switching: Switching between threads within a process is
generally faster than switching between processes due to shared
resources.
Types:
• Fine-Grained Multi-Threading: Threads are switched rapidly to
maximize CPU utilization. Often used in scenarios with high
computational needs and frequent context switches.
• Coarse-Grained Multi-Threading: Threads are switched less
frequently, typically used in scenarios where each thread performs
longer-running tasks.
Applications:
• Parallel Processing: Improves performance of applications by
parallelizing tasks such as web servers handling multiple requests or
applications performing simultaneous computations.
• Responsiveness: Enhances the responsiveness of applications by
allowing background tasks to run concurrently with the main
application logic.
Advantages:
• Improved Utilization: Utilizes CPU resources more effectively by
running multiple threads in parallel.
• Efficiency: Faster context switching compared to process-level
parallelism, leading to improved performance in multi-threaded
applications.
Challenges:
• Concurrency Issues: Requires careful management of shared
resources to avoid issues such as race conditions and deadlocks.
• Complex Debugging: Debugging multi-threaded applications can
be complex due to potential concurrency issues and synchronization
challenges.
Comparison with MIMD:
• Instruction and Data: MIMD involves multiple processors executing
different instructions on different data, while multi-threading involves
multiple threads within a single process sharing the same memory
space.
• Memory Model: MIMD can be either shared or distributed memory,
whereas multi-threading typically uses shared memory within a
process.
• Scalability: MIMD can scale across a large number of processors,
whereas multi-threading is limited by the number of cores available
in a single system.
Comparison:
• Memory Access:
•Distributed Memory: Each processor has its own local
memory; communication requires explicit message passing.
• Shared Memory: All processors share a common memory
space; communication is implicit through memory reads and
writes.
• Scalability:
•Distributed Memory: Generally more scalable due to
independent memory spaces.
• Shared Memory: Scalability can be limited by memory access
contention and synchronization overhead.
• Complexity:
• Distributed Memory: More complex programming model
requiring explicit communication.
• Shared Memory: Simplified programming model but requires
careful management of synchronization and cache coherence.