How does multithreading speed up applications (threads cannot run at the same time)?

I'm learning multithreading, but after reading some tutorials, I'm confused

Intuitively, I would say that multithreading slows down applications because you keep waiting for these semaphores

How and when can multithreading speed up an application when threads cannot run at the same time?

Solution

I can think of two ways, the first of which may mean "parallel thread"

>If you have multiple CPUs or cores, if you are running multiple threads, they can work at the same time. > In the case of a single core, if your thread finally waits for (synchronizes) I / O, suppose you call read() to read 100 MB from the tape, and another thread can get scheduled and complete its work while waiting

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>