A feature within a CPU that allows two or more instruction streams (threads) to execute concurrently. Each stream is a "subprocess" that is managed by the CPU and operating system. Multithreading takes advantage of the superscalar architecture in most CPUs combined with the fact that while one operation takes place, very often another can proceed simultaneously. For example, as soon as an instruction to output data to storage is given, a huge number of data processing instructions (compare, copy, goto, etc.) can be executed while storage is being written. Depending on the program logic, instructions can be executed out of sequence and benefit from some overlap.
Both operating systems and applications may be written to use threads. However, designing the program logic for multithreading that ensures instructions are always executed without conflict can be a daunting task.
Multicore vs. Multithreading
Multicore CPUs have two or more processing cores, each capable of executing instructions in parallel. In fact, except for low-cost microcontrollers, most CPUs have two or more cores. In contrast, multithreading occurs within a single processing core to increase performance approximately 25%. Each thread is a "logical core" rather than a physical core. See microcontroller
Today's CPUs generally support at least two threads per core, but some handle many more. For example, IBM's POWER10 CPU comes with up to 15 cores, and each core handles eight threads for a total of 120 threads. Tasks such as video rendering and machine vision, which perform millions of identical calculations on a matrix of pixels, are candidates for multithreading. See superscalar
, re-entrant code
Each of these two cores in this dual-core CPU example is executing instructions independently of the other. The arrows point to the two machine instructions being executed at the moment.
Dual Cores and Two Threads
Each core has two threads, which provides some degree of overlap within the routines that are executing simultaneously. If both threads in both cores are executing, four operations are taking place simultaneously.
The cover of Software Development Times in November 2012 highlighted the issue that CPUs with many cores provide more channels of parallel instruction execution.