Thread

A thread is the smallest unit of execution within a process. It allows a program to perform multiple tasks at the same time.

A single process can contain one or multiple threads.

How it works

When a program runs, the operating system creates a process. Inside that process, one or more threads can be created to handle different tasks.

Threads share the same memory space and resources of their parent process, but each thread has its own execution path.

The scheduler manages threads and decides which one uses the CPU at a given moment.

Thread vs Process

  • A process is an independent running program.
  • A thread is a smaller task inside a process.

Processes are isolated from each other, while threads within the same process share memory.

Because threads share resources, they are lighter and faster to create than processes.

 

Why it is important

  • It improves multitasking within applications.
  • It increases performance in modern systems.
  • It allows background tasks to run smoothly.

For example, one thread can handle user input while another loads data in the background.

Single-threaded vs Multi-threaded

  • Single-threaded applications run one task at a time.
  • Multi-threaded applications can perform multiple operations simultaneously.

Modern software often uses multi-threading for better efficiency.

A simple example

In a web browser, one thread may load a webpage while another handles scrolling or user interaction.

Related terms

Source

Information simplified from the Wikipedia article “Thread (computing)”.

Nach oben scrollen