Multithreading: What is the point of more threads than cores?

后端 未结 17 939
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-29 16:24

I thought the point of a multi-core computer is that it could run multiple threads simultaneously. In that case, if you have a quad-core machine, what\'s the point of having

17条回答
  •  执念已碎
    2020-11-29 17:10

    I strongly disagree with @kyoryu's assertion that the ideal number is one thread per CPU.

    Think about it this way: why do we have multi-processing operating systems? For most of computer history, nearly all computers had one CPU. Yet from the 1960s on, all "real" computers had multi-processing (aka multi-tasking) operating systems.

    You run multiple programs so that one can run while others are blocked for things like IO.

    lets set aside arguments about whether Windows versions before NT were multi-tasking. Since then, every real OS had multi-tasking. Some don't expose it to users, but its there anyway, doing things like listening to the cellphone radio, talking to the GPS chip, accepting mouse input, etc.

    Threads are just tasks that are a bit more efficient. There is no fundamental difference between a task, process, and thread.

    A CPU is a terrible thing to waste, so have lots of things ready to use it when you can.

    I will agree that with most procedural languages, C, C++, Java etc, writing proper thread safe code is a lot of work. With 6 core CPUs on the market today, and 16 core CPUs not far away, I expect that folks will move away from these old languages, as multi-threading is more and more of a critical requirement.

    Disagreement with @kyoryu is just IMHO, the rest is fact.

提交回复
热议问题