multithreading on dual core machine?

前端 未结 5 2191
無奈伤痛
無奈伤痛 2020-12-05 21:30

I have a dual core processor and according to the explanation I\'m able to use only 2 threads but actually I\'m able to launch more than 2 threads at same time:

Here

相关标签:
5条回答
  • 2020-12-05 21:40

    You can use more threads than you have processor cores. This can have several benefits: you can hide communication (e.g., file I/O or network) with computation, or get more processor time in time-slicing systems. With two cores, only two threads will physically be executing at the same time, but having more threads can increase performance. It's something you need to tune.

    0 讨论(0)
  • 2020-12-05 21:47

    The term threads usually covers three abstraction layers:

    1. User threads are threads launched by applications and are mapped N:M to:
    2. Kernel threads, which are threads managed by the operating system, mapped N:M to:
    3. Hardware threads, which are the actual physical resources available.

    The 4 threads you said are launched by the application are from category 1 (user threads), while the value 2 returned by that function refers to category 3 (hardware threads). Since the mapping is N:M across the layers, you can see that you can have several user threads mapped to a smaller number of hardware threads.

    Having said this, typically starting more than 2x the number of hardware threads if you are doing intensive computations will hurt performance due to context switches and resource contention.

    0 讨论(0)
  • 2020-12-05 21:51

    There's a difference between optimal and possible results; there also is a difference between threads phisically and theoretically running at the same time. In a dual-core computer, there are 2 CPUs, that are able to execute two threads phisically at the same time. But the significance of any threading system/thread library is that you are able to create logically as meany threads as you want. These threads won't really run at the same time, they'll be switched over periodically instead to make the illusion as if they were running simoultaneously.

    0 讨论(0)
  • 2020-12-05 21:51

    The first called paralell programming and the second one is multi tasking which can be done even in a single processor machine

    0 讨论(0)
  • 2020-12-05 21:59

    You can always run multiple threads, even on single core machine. Though, they can't run in parallel. (more than 2 in your case)

    For example, one thread does the GUI, the other fetches some work from the server...

    See this for a deeper explanation.

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