A thread is the unit of execution within a process. We can say that a collection of threads is known as a process.
<aside> 💡 Early computers only supported one thread per process.
</aside>
Multithreading is the process of executing multiple threads at the same time.

Processors actually can only execute one instruction at a time, but it switches between different threads extremely fast, giving the illusion of simultaneous execution. This is called context switching.
A context switch captures the CPU state (the context) of the current running thread, and pauses it to swap with another thread and resume where it previously left off.
Context switching enables all processes to share a single CPU to finish execution and store the status of the system’s task. It is usually triggered by interrupts, multitasking, and user/kernel switching.
<aside> ⚠️ Programmers need to be careful about managing threads to avoid problems like conflicts or situations where threads get stuck waiting for each other. This is called a deadlock.
</aside>
Multitasking is the process of running multiple programs or tasks concurrently. Multithreading can load a web browser page while listening for user input, whereas multitasking allows you to listen to music while browsing the web.
Threading is a segment of divided pieces of code that are lightweight and has less burden on CPU memory.
User-level threads: These threads are managed in the user-space, meaning the OS does not support the threads. User-level threads can be faster to create and switch between because they avoid kernel mode context switching, but they lack the kernel's support for multi-core scheduling. As a result, user-level threads are less capable of achieving parallelism in multi-core systems.
Kernel-level threads: These threads are managed directly by the operating system's kernel. The kernel handles thread creation, scheduling, and management, allowing for true parallelism on multiprocessor systems. The ability to have full control over all aspects of threading made kernel-level threads the ideal model for modern systems.
Thread lifecycle
