Contents

Computer Science › Computer Architecture

CPU Core

An independent processing unit; modern CPUs have several.

Also known as: core, multi-core, CPU cores, threads

A core is an independent processing unit inside a CPU. A chip with four cores can genuinely run four streams of instructions at the same time. Almost all modern CPUs have several: a phone might have 8, a server dozens.

import os
os.cpu_count()        # logical CPUs the machine reports

Cores vs threads

  • A core is a physical processing unit.
  • Some CPUs offer hardware threads (hyper-threading, SMT): one core presents itself as two logical CPUs, sharing its resources. Software sees twice the count, but you don’t get twice the speed.
  • An operating-system thread is a software sequence of instructions that the OS schedules onto a core. You can have far more threads than cores, and the OS takes turns.

Why it matters

Programs only speed up on multiple cores if their work can be split and run in parallel (concurrency vs parallelism). A single-threaded program uses one core, however many exist.

  • Python: because of the GIL, threads can’t run Python code in parallel. Use multiple processes for CPU-bound work.
  • JavaScript runs your code on one thread. Use workers for parallel work.
  • Go, Java, Rust, C# can use many cores with threads.
  • I/O-bound work doesn’t need many cores. It needs concurrency, such as async.

Practical points

  • Size thread and process pools from the core count, but measure.
  • Containers and cloud instances may be limited to a fraction of a core. A “0.5 CPU” limit throttles a busy program.
  • Shared data between threads needs care: race conditions, locks.
  • More cores don’t fix a slow algorithm.
  • Amdahl’s law says the part that can’t be parallelized limits the speedup (Amdahl’s law).