Thread & Process

CPU Threads and Processes: Similarities and Disparities

Hardware

First-thing-first: CPU multitasking, also known as multitasking or multiprogramming, is the ability of a computer's central processing unit (CPU) to execute multiple tasks concurrently. Instead of completing one task at a time, a multitasking system allows for the interleaved execution of multiple tasks, seemingly simultaneously.

Threads and Processes:

A thread is a single sequence stream within a process. Because of some properties of processes, they are called lightweight processes. In a process, threads allow multiple executions of the streams. The CPU switches rapidly back and forth among the threads giving illusions that the threads are running in parallel. Like, a traditional process i.e., a process with one thread, a thread can be in any of several states(running, blocked, ready, or terminated). Each thread has its stack. since threads generally call different procedures and thus a different execution. This is why the thread needs its stack.

CPU Threads & Processes

In an operating system that has a thread facility, the basic unit of CPU utilization is a thread. Threads are executed one after another thread has different states. It has a program counter, register set stack space. Threads are not independent of each other as they share the code, data, OS resources, etc.

In a thread-based operating system, a process consists of an address space and one or more threads. Each thread of a process has its program counter, register states, and stack. But all threads of a single process share the same address space.

Now let's explore each concept:

Threads Processes
A thread is the smallest unit of execution within a process. A process is an independent program in execution. It has its own memory space, resources, and a unique process identifier (PID).
In a multi-threaded environment, a process can have multiple threads, each running concurrently. Each process typically runs in its own address space, isolated from other processes, providing memory protection.
Threads within a process share the same resources, such as memory space, but have their own program counter, register set, and stack. Processes can contain one or multiple threads. A single-threaded process has only one thread of execution, while a multi-threaded process has multiple threads working together.
Multi-threading allows for parallel execution of tasks within a process, potentially improving performance on multi-core processors. Processes are managed by the operating system's process scheduler, which allocates CPU time and resources to each process.

In summary, a process is a self-contained unit of execution with its own memory and resources, while a thread is the smallest unit of execution within a process. Multiple threads within a process can run concurrently and share resources, allowing for parallelism and improved performance on multi-core processors.

Here's a simple analogy: Think of a process as a program, and threads as individual tasks within that program. If you have a word processing application running, the process is the application itself, and each thread might handle different tasks like user interface responsiveness, spell checking, and document printing.

Note: The distinction between processes and threads is crucial for understanding how modern operating systems manage and execute tasks efficiently, especially in environments with multiple processor cores.

Category: Hardware

on: 16 Dec 2020

on: 18 Feb 2022

What's Next?

We've now entered the finance section on this platform, where you can enhance your financial literacy.