Does multithreading always yield better performance than single threading?

前端 未结 7 1742
自闭症患者
自闭症患者 2020-12-25 08:03

I know the answer is No, here is an example Why single thread is faster than multithreading in Java? .

So when processing a task in a thread is triv

7条回答
  •  生来不讨喜
    2020-12-25 08:49

    Are there more cases where a single thread will be faster than multithreading?

    So in a GUI application you will benefit from multithreading. At the most basic level you will be updating the front end as well as what the front end is presenting. If you're running something basic like hello world then like you showed it would be more overhead.

    That question is very broad... Do you count Unit Tests as applications? If so then there are probably more applications that use single threads because any complex system will have (hopefully) at least 1 unit test. Do you count every Hello world style program as a different application or the same? If an application is deleted does it still count?

    As you can see I can't give a good response other than you would have to narrow the scope of your question to get a meaningful answer. That being said this may be a statistic out there that I'm unaware of.

    When should we decide to give up multithreading and only use a single thread to accomplish our goal?

    When multithreading will perform 'better' by whatever metric you think is important.

    Can your problem be broken into parts that can be processed simultaneously? Not in a contrived way like breaking Hello World into two threads where one thread waits on the other to print. But in a way that 2+ threads would be able to accomplish the task more efficiently than one?

    Even if a task is easily parallelizable doesn't mean that it should be. I could multithread an application that trolled thousands of new sites constantly to get me my news. For me personally this would suck because it would eat my pipe up and I wouldn't be able to get my FPS in. For CNN this might be exactly what they want and will build a mainframe to accommodate it.

    Can you narrow your questions?

提交回复
热议问题