Professional Documents
Culture Documents
Quiz 2
Quiz 2
QUIZ - 02
Page | 1
1. Compare Single threaded vs Multi-threaded.
Single-threaded Multi-threaded
In a single-threaded application, there is only one In a multi-threaded application, multiple threads
sequence of instructions being executed at a time. are used to execute tasks concurrently. Each
This means that tasks are processed one after the thread represents a separate flow of execution,
other in a linear fashion. allowing multiple operations to be performed
simultaneously.
Performance
Multi-threaded applications can potentially offer Single-threaded applications are limited to the
better performance by leveraging multiple CPU processing power of a single core.
cores and executing tasks concurrently.
Complexity
Multi-threaded programming can be more Single-threaded applications are typically simpler
complex and error-prone due to issues like race to design and debug.
conditions, deadlocks, and thread synchronization.
Resource Utilization
Multi-threaded applications can make more Single-threaded applications may underutilize
efficient use of available resources, especially in resources if they're not designed to take advantage
scenarios where tasks can be executed of parallelism.
independently and concurrently.
Scalability
Multi-threaded applications can scale better on Single-threaded applications may struggle to scale
multi-core systems or in environments with high in such scenarios due to their sequential execution
concurrency requirements. model.
Example
A web server handling multiple client requests A simple calculator program that performs
concurrently, with each request being processed calculations one after the other without any
by a separate thread. parallel processing.
Page | 2
Performance
User-level threads generally have lower Kernel-level threads may have higher
overhead for thread creation, context overhead due to involvement of the kernel in
switching, and synchronization since they are thread management.
managed entirely in user space.
Concurrency
User-level threads may be limited to pseudo- Kernel-level threads can achieve true
parallelism on a single core. parallelism by running concurrently on
multiple CPU cores.
Portability
User-level threads are more portable across Kernel-level threads may be more efficient on
different operating systems since they rely on some operating systems but may lack
user-space libraries. portability.
Example
Java threads managed by the Java Virtual POSIX Threads (pthreads) with kernel-level
Machine (JVM) implementation
Page | 3