Computer Processor & Threading Cheat Sheet


    • The CPU (Central Processing Unit)
      • What it is: The "brain" of the computer.
      • What it does: Executes instructions using the Fetch-Decode-Execute cycle.
      • Key Specs:
        • Cores: Independent processing units inside the CPU. More cores = more true multitasking.
        • Clock Speed (GHz): The number of cycles per second. Higher is generally faster.
        • Cache (L1/L2/L3): Tiny, ultra-fast memory on the CPU for frequently used data.

    • Process vs. Thread
    FeatureProcess (e.g., Google Chrome)Thread (A Tab in Chrome)
    AnalogyA self-contained KitchenA Cook working in the kitchen
    ResourcesHas its own private memory & resourcesShares memory with other threads in its process
    WeightHeavyweight (slow to create)Lightweight (fast to create)
    IsolationIsolated from other processes (stable)Not isolated from its sibling threads
    Unit OfResource OwnershipExecution (What the CPU runs)
    • The Relationship with the CPU
      • The Operating System (OS) Scheduler is the manager.
      • The OS schedules Threads, not processes, to run on CPU cores.
      • Single-Core CPU: Achieves multitasking via Concurrency (fast switching/time-slicing). Gives the illusion of parallel execution.
      • Multi-Core CPU: Achieves True Parallelism. A 6-core CPU can run 6 threads at the exact same time.

    • How Many Threads Can Run?
      • At the Same Time (In Parallel):
        • The number is limited by the CPU’s Logical Cores
        • Rule: 1 Thread per Logical Core.
        • Example: A 6-core CPU without Hyper-Threading runs 6 threads in parallel. A 6-core CPU with Hyper-Threading runs 12 threads in parallel.
      • In Total (Existing in the System):
        • The number is limited by RAM and OS configuration.
        • Can be tens of thousands.
        • Most of these threads are either Ready (waiting for a CPU core) or Waiting/Blocked (waiting for I/O like disk or network).

    • Finding the Optimal Thread Count (Performance Tuning)
      • The ideal number of threads depends entirely on the type of workload
    Workload TypeDescriptionOptimal Threads on a 6-Core CPUReason
    CPU-BoundConstant calculation (e.g., video rendering). The CPU is the bottleneck.6Maximizes core usage without the waste of context-switching.
    I/O-BoundFrequent waiting (e.g., file downloads). The disk/network is the bottleneck.>> 6 (e.g., 20-100+)Hides I/O latency. While one thread waits, another uses the CPU.

    The Ultimate Rule: Don’t Guess, Measure! Start with a number of threads equal to your core count and benchmark your application, increasing the thread count to find the “sweet spot” for your specific task.