I wanted to know how does a multi-threaded program with more number of threads executes on a processor core. For example, my program has 12 threads and I am running it on a intel core-i5 machine. It has four CPUs. Will each core run 3 threads? I am confused because I have seen programs with 30 threads running on a 4 core machine.
Thanks
In computer architecture, multithreading is the ability of a central processing unit (CPU) (or a single core in a multi-core processor) to provide multiple threads of execution concurrently, supported by the operating system. This approach differs from multiprocessing.
Instead of giving a large workload to a single core, threaded programs split the work into multiple software threads. These threads are processed in parallel by different CPU cores to save time. Depending on how they're built, games may be lightly threaded or heavily threaded.
A single CPU core can have up-to 2 threads per core. For example, if a CPU is dual core (i.e., 2 cores) it will have 4 threads.
With multithreading, while the computer system's processor executes one instruction at a time, different threads from multiple programs are executed so fast it appears the programs are executed simultaneously.
A core is responsible for executing thread cycles. The more cores you have, the more threads you may run simultaneously. Each core can execute only one instruction at a time, however it’s so fast it seems as if you are running multiple threads simultaneously.
Intel Processors
supports Hyper Threading enabling a single core to support multiple Threads as operating system
sees twice the amount of logical cores per physical core. For instance, a Core i3, which is only a dual core, can actually serve two threads per core i.e. total of four threads can run simultaneously. However even if Core i5 processors
are quad cores, since they don’t support Hyper-Threading (except the i5-661) the number of threads they can serve at the same time is just about equal to those of their Core i3
counterparts.
Each core would be able to execute one thread simultaneously. So if there are 30 threads and 4 cores, 26 threads will be waiting to get context switched to get executed. Something like, thread 1-4 runs for 200ms and then 5-8 runs for 200 ms and so on
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With