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

后端 未结 17 933
爱一瞬间的悲伤
爱一瞬间的悲伤 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:07

    The way some API are designed, you have no choice but to run them in a separate thread (anything with blocking operations). An example would be Python's HTTP libraries (AFAIK).

    Usually this isn't much of a problem though (if it is a problem, the OS or API should ship with an alternative asynchronous operating mode, ie: select(2)), because it probably means the thread is going to be sleeping during waiting for I/O completion. On the other hand, if something is doing a heavy computation, you have to put it in a separate thread than say, the GUI thread (unless you enjoy manual multiplexing).

提交回复
热议问题