Nepedia
Back to Discover
Advanced Reader
💻

Multithreading (computer architecture)

technology Maturity 7-9 Next article →

Multithreading is a method used in computer architecture to increase efficiency. It allows a central processing unit (CPU), or a single core, to provide multiple threads of execution. A thread is essentially a path of work within a computer program. Since the late 1990s, engineers have used multithreading to improve throughput computing. This is important because making a single thread run faster has become very difficult. Instead of focusing on one task, computers now focus on finishing more total work.

To understand how this works, we must look at why a CPU might sit idle. Sometimes, a thread hits a stall, which is a long pause in work. This often happens during a cache miss, when the CPU must wait for data from off-chip memory. This wait can last for hundreds of CPU cycles. In a multithreaded system, the processor does not just sit still during this wait. Instead, the hardware switches from the stalled thread to another thread that is ready to run. This process keeps the computing resources busy and improves overall performance.

There are several distinct types of multithreading used in modern computers. The simplest version is known as block, cooperative, or coarse-grained multithreading. In this type, one thread runs until it is blocked by a specific event. To make switching fast, the hardware often replicates certain parts. For example, the processor might be built with two sets of registers. Registers are small storage areas that hold a thread's current information. By having multiple sets, the hardware can switch between threads very quickly.

Another type is fine-grained multithreading, which is also called interleaved or time-sliced multithreading. This method is more aggressive because it switches threads every single CPU cycle. This approach aims to remove all data dependency stalls from the execution pipeline. In the past, this was sometimes called barrel processing. This name comes from the idea that the pipeline stages act like the staves of a barrel. However, this method has extra hardware costs. Each stage of the pipeline must track the thread ID of every instruction it processes.

Simultaneous multithreading (SMT) is the most advanced type of this technology. While other types are called temporal multithreading because they issue one thread at a time, SMT is different. An SMT processor can issue instructions from multiple different threads during the very same CPU cycle. This is used in superscalar processors to fill unused issue slots. By using instructions from many threads at once, the processor exploits parallelism across the entire system. This prevents the waste that occurs when a single thread cannot use all available resources.

Many major technology companies have implemented these advanced methods. Intel uses a version of SMT called Hyper-Threading Technology. IBM uses it in their POWER and z13 through z15 series chips. AMD also uses SMT in their Bulldozer and Zen microarchitectures. Sun Microsystems used it in the UltraSPARC T2, and Cray produced the XMT. These different implementations show how vital multithreading has become to high-performance computing.

While multithreading is powerful, it does have some significant disadvantages. Multiple threads often share hardware resources like caches or translation lookaside buffers (TLBs). When threads fight over these shared parts, it is called contention. This contention can actually degrade the performance of a single thread. Furthermore, merging data from two different processes can be very expensive. This overhead, caused by synchronization and inter-process communication, can be two or more orders of magnitude higher than single-thread processing.

Despite these challenges, the benefits can be quite large. Intel claims that Hyper-Threading can provide up to a 30% improvement in efficiency. In some cases, a synthetic program can see a 100% speed improvement when run in parallel. However, not all software benefits from this. For instance, hand-tuned assembly language programs, like some video encoders, do not suffer from idle resources. These specialized programs might actually see slower performance when hardware multithreading is active.

656 words

Where will your curiosity go next?

Keep exploring at your chosen reading level.

🖼️ Images & Media (1)
File:Multithreaded process.svg
Multithreaded process.svg
More to explore

What is Nepedia?

A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.