multithreading on dual core machine?

前端 未结 5 2194
無奈伤痛
無奈伤痛 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条回答
  •  Happy的楠姐
    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.

提交回复
热议问题