Does it make sense to spawn more than one thread per processor?

前端 未结 9 1207
面向向阳花
面向向阳花 2020-12-10 16:15

From a logical point of view an application may need dozens or hundreds of threads, some of which will we sleeping most of the time, but a very few will be always running co

相关标签:
9条回答
  • 2020-12-10 16:50

    This may make sense if

    1. your program design benefits, in that you have parallel tasks that are best implemented in threads, or

    2. some of your threads are I/O-bound, so they do not utilize the processors /cores on their own.

    0 讨论(0)
  • 2020-12-10 16:53

    According to Herb Sutter (one of the leading experts on concurrency), one of the Pillars of Concurrency is Responsiveness and Isolation Via Asynchronous Agents. The summary is:

    Stay responsive by running tasks independently and tasks asynchronously, communicating via messages.

    Great article (and the series as a whole!). I am still waiting for the book.

    0 讨论(0)
  • 2020-12-10 16:55

    Because all modern OS are multi tasking: each thread gets a time share from the processor. It is not actually concurrent execution but given the processor can handle thousands of requests per sec, it is an "apparent" concurrent execution.

    So yes, if the case needs, it does make sense to multi-thread on a single processor.

    0 讨论(0)
提交回复
热议问题