Thread
A thread is the smallest unit of processing that can be performed in an operating system (OS). It is a part of a process, which is a program in execution. Threads allow a process to perform multiple tasks simultaneously, improving efficiency and performance. Example (Wedding – Explanation in class). Threads exist within a process — every process has at least one. Threads share the process’s resources, including memory and open files. This makes for efficient, but potentially problematic, communication.
Multi-Threading
Multithreading is a programming technique that allows concurrent execution of two or more threads (lightweight sub-processes) within a single program. It is a form of multitasking that enables efficient use of system resources and improves the performance of applications, especially on multi-core processors.
CPU Core
A CPU core is a single processing unit within a computer’s central processing unit (CPU). It reads and executes instructions from programs, performing basic arithmetic, logic, control, and input/output operations specified by the instructions.
With more cores, a computer can handle multiple applications running at the same time.
Modern CPUs have multiple cores, commonly found in configurations like dual-core (2 cores), quad-core (4 cores), hexa-core (6 cores), octa-core (8 cores), and more. Each core can handle a separate task simultaneously.
Parallelism in Single Core
Even though a single-core CPU can only execute one instruction at a time, it can still achieve a form of parallelism through several techniques.
Multitasking with Context Switching: The CPU switches rapidly between different tasks, executing a few instructions from each task in turn. This switching is so fast that it appears as if the tasks are running simultaneously.
Time Slicing: The CPU time is divided into small units called time slices. Each task gets a time slice to execute its instructions before the CPU switches to the next task.
Interrupt Handling: The CPU can be interrupted to handle high-priority tasks or events, temporarily pausing the current task.
Types of Multi-Tasking
- Process based: A process is a program executing. eg Java compiler, Browser, VSCode, etc. Process-based multitasking is the feature that allows your computer to run two or more programs concurrently.
- Thread based: Thread is the smallest unit of dispatchable code. In thread based multi-tasking, a single program can perform two or more tasks simultaneously. Multitasking threads require less overhead than multitasking processes