Single- vs. multi-threaded programming on a single core processor

后端 未结 3 1476
野的像风
野的像风 2021-02-01 07:54

Can someone please explain if there\'s really any advantage to writing a multi-threaded piece of code that runs on a single processor with a single core? E.g., a method that pr

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-01 08:32

    There are still advantages to be gained, but they're a bit situational.

    • In many cases, giving the thing multiple threads will allow it to claim more system resources from other processes. This is finicky to balance, and each thread you introduce adds a bit of overhead, but it can be a reason.

    • If you are dealing with multiple potentially blocking resources - like file IO or GUI interaction or whatnot, then multithreading can be vital.

提交回复
热议问题