By definition, a thread is a lightweight process.
A thread is made up of a stack, a set of registers, and its own program counter. Through parallelism, threads assist us in giving applications great performance. The CPU rapidly changes between the threads, creating the appearance that they are working simultaneously.
User threads and kernel threads are the two types of threads.
Application program threads are essentially user threads. As opposed to this, kernel threads allow the OS kernel to handle numerous concurrent kernel system calls and/or complete several concurrent activities. Kernel threads are assigned to the user threads.
Multithreading
This method uses the operating system to execute many threads simultaneously. There are numerous ways for mapping user threads to kernel threads, including many-to-one, one-to-one, and many-to-many.
Many-to-One Model
Many user-level threads are mapped onto a single kernel thread in the many-to-one approach. The efficient thread library in user space is responsible for thread management.
One-to-One Model
With the one-to-one paradigm, each and every user thread is handled by a separate kernel thread. The majority of this model's implementations impose a cap on the number of threads that can be created. The one-to-one paradigm for threads is implemented in Linux and Windows from 95 to XP.
Many-to-Many Model
The many-to-many model combines the best aspects of the one-to-one and many-to-one models by multiplexing any number of user threads onto an equal or less number of kernel threads. Any number of threads can be started by users. The process is not entirely stopped if the kernel system calls are blocked. Multiple processors can be used to divide up processes.
Benefits of Multithreading
Responsiveness: Resource sharing, hence allowing better utilization of resources.
Economy: Creating and managing threads are easier and threads are comparatively less resource consuming than processes.
Scalability: On one CPU, one thread is active. Threads in multi-threaded processes can be spread across a number of processors to scalability.
Multithreading Issues
Below we have mentioned a few issues related to multithreading. Well, it's an old saying, all good things, come at a price.
Thread Cancellation: Terminating a thread before it has finished working is referred to as thread cancellation. There are two possible strategies for this. The first is asynchronous cancellation, which immediately kills the target thread. The other is Deferred cancellation, which enables the target thread to check for cancellation on a regular basis.
Signal Handling: In UNIX systems, signals are used to inform a process that a specific event has taken place. Now, which thread must a signal be transmitted to when a multi-threaded process gets one? It can be sent to every topic or just one specific one.
fork() System Call: A process can make a replica of itself by using the system function fork(), which is carried out in the kernel. The question now is whether or not the entire multi-threaded process will be replicated if one thread forks.
Security Issues: Yes, due to the considerable resource sharing between numerous threads, there may be security concerns.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.