What are the “Threads” of a CPU and why do they exist?

628 views

What are the “Threads” of a CPU and why do they exist?

In: 1

5 Answers

Anonymous 0 Comments

A thread is basically a separate program. When a CPU runs a program it goes through line by line in the order listed in the program code.

Many OSs are designed to allow multiple programs to run on one CPU by periodically interrupting the CPU and reconfigure the CPU to work on a different program. This is “multi-tasking”. If a comouter has more than one CPU available, then the OS can configure individual CPUs to run separate programs simultaneously, instead of periodically stepping in and telling the CPU to do something different.

So what happens when a CPU runs a program. It has a memory control circuit which retrieves a line of program code. It then activates a decoder circuit which works out what the code is meant to do – for example, if it is a retrieve from memory instruction it engages the memory control circuit to retrieve the information; if it is a multiply instruction, the decoder engages the multiply circuit. Once the instruction is done, the cycle repeats and the next line of code is retrieved and decoded and executed.

You will notice that because a CPU has a ton of different components, like multiply circuits, add circuits, compare circuits, memory control circuits, most of the time they are sat there doing nothing. The circuits are only engaged when needed.

A trick that CPU makers have used is to out two decoder circuits in one CPU. Each decoder runs one program, so a two decode CPU acts a bit like having 2 separate CPUs. So let’s say decoder 1 is running program 1, and the next line is a multiply. Decoder 1 engages the multiply circuit. Simultaneously, decoder 2 gets the next line of program 2, this is an addition, the addition circuit is free, so it engages it. So both the multiplier and adder circuit are simultaneously engaged.

This allows two programs to share a CPU and make more efficient use of the circuits, but instead of having 2 separate CPUs costing money, taking up space and using power, you just have 1 CPU with an extra decoder circuit. It’s not as good as 2 separate CPUs( if 2 additions come in one will have to wait) but it’s a lot cheaper.

Modern PCs often have multiple CPUs – 4 to 8 CPUs are common in modern computers and phones. In PCs these multiple CPUs also can each run multiple threads. So a 4 CPU system could potentially run 8 threads (programs) simultaneously.

You are viewing 1 out of 5 answers, click here to view all answers.