Glossary · Programming

Thread

A thread is the smallest unit of execution within a process, letting a program run several tasks concurrently while sharing the same memory.

Updated October 6, 2026

A thread is an independent path of execution inside a process. All threads in a process share the same memory, but each has its own call stack and instruction pointer, so a program can do several things at once.

Why it matters

Threads let a program use multiple CPU cores and keep working while one task waits for input or output. A web server may handle each request on its own thread. Because memory is shared, threads can interfere with each other, which causes race conditions and deadlocks, so access to shared data must be coordinated with locks or other tools.

Example

import threading

def worker(n):
    print("task", n)

threads = [threading.Thread(target=worker, args=(i,)) for i in range(3)]
for t in threads: t.start()
for t in threads: t.join()

Three threads start and the main thread waits for all of them. Output order can differ between runs, which is normal.

Common mistakes

  • Sharing mutable data without a lock, causing unpredictable results.
  • Creating a new thread per tiny task instead of using a thread pool.
  • Confusing threads with processes; processes have separate memory, threads do not.

Get notified when this term updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.