How can multithreading speed up an application (when threads can't run concurrently)?

前端 未结 9 1985
忘掉有多难
忘掉有多难 2020-12-31 09:11

I\'m learning about multithreading, but after reading some tutorials I\'m sort of confused. I don\'t understand how multithreading can speed up an application.

By in

9条回答
  •  攒了一身酷
    2020-12-31 09:55

    On a computer, many programs (or threads) share some resources. Suppose one thread is waiting for a specific resource (for example, it wants to write data to disk). OS can then switch to another tread to be able to continue computing using available resources. This is why it is often a good idea to put I/O operations on a separate thread, and also to put GUI in a separate thread.

    Off course, multithreading will not gives you a perfect speedup, but it can help a little big increasing performances. It is even better on hyperthreading architectures, where some registers are duplicated to minimize impact of context switching.

提交回复
热议问题