Whenever you run your application, there are so many moving parts.
The key parts are the CPU, the cores and the thread.
In this lesson, you will learn to tell the difference between CPU, core and thread.
Now, a CPU is often referred to as a processor, and most computers only have one CPU chip.
And so why is a CPU called the processor?
That's because it uses processing units called course to execute instructions.
The following is a four core CPU.
Think of every corner as a worker.
Whenever we write code, we're writing instructions.
And when we were in our application, we're running our code on a thread.
This thread contains the instructions that we programmed and all of the instructions that we programmed
on this thread.
They're sent over to the processor.
We're sending these instructions to the processor and it's the cause the workers inside the processor
that execute tasks based on the instructions that the thread provides.
And it follows that the more cores you have, the more instructions that can be processed at the same
time.
Here's an exercise for you.
Go on Google and look up how to check the number of CPU cores inside your machine.
We'll give you some time to parse the video.
OK.
As of this recording, I'm using a MacBook Air M1, which has an eight core CPU.
OK, now what is a thread, a thread is a path of execution.
The instructions in your app run on a thread.
Going back to our diagram, each thread acts as a pathway for instructions to flow through.
Now, this is really important.
So far, every application that we built in this course has been single threaded.
I want to repeat this one more time.
Every application that we built in this course has been single threaded.
So every time we ran our single threaded application, the instructions were being run on a single thread.
Our thread is like a conveyor belt of instructions and eventually every instruction is processed by
the core and our core.
Our worker processes tasks based on the instructions that it receives.
Now, a multi-threaded application runs on many threads.
When you run a multi-threaded application, different parts of the code are running on different threads.
This can be more efficient because different parts of your code are being processed at the same time.
And so once again, each threat is like a conveyor belt of instructions, and eventually every instruction
gets processed by a court which performs tasks based on the instructions that it receives.
And once every instruction has been processed, you in essence, run your application.
Let's talk about the main thread.
By default, your application is single threaded.
The thread your code runs on is known as the main thread.
If I run the following code, it's going to run it on the main thread.
In other words, the series of instructions we programmed execute on the main thread, and the main
thread is like a conveyor belt that passes every instructions to a single core and the core inside of
your computer.
It performs tasks based on the instructions that it receives from your main thread, thereby running
your application.
OK, let's recap what we learned so far.
A CPU chip has multiple cores in each core is a worker that can perform tasks based on the instructions
that it receives.
Each thread is a conveyor belt of instructions that a core eventually processes.