Home > Software design >  Did cpu workload increased linearly in multithreading?
Did cpu workload increased linearly in multithreading?

Time:01-26

If a single thread cost 25% workload of a multi-core CPU, are 4 threads will fill the CPU?

Besides the 4 threads, can I do something else with the CPU?

CodePudding user response:

If a single thread uses 25% of the CPU, then what is using the other 75%?

If the answer is, nothing is using the other 75%—if the CPU is idle 75% of the time—then the single thread is not cpu-bound. That is to say, something other than the availability of CPU cycles is limiting the speed of the program.

What is blocking the thread? Probably the thread is awaiting some resource; messages from the network, disk I/O, user input, etc. Whatever it is, if there are at least four of them, and if your program can be structured to concurrently use four of them, then maybe running four threads will allow the program to run four times as fast.

An example would be, if your program is some kind of a server, and it spends a lot of time awaiting messages from clients, then adding more threads would allow it to simultaneously await more messages, and it would improve the throughput.

A counterexample would be if your program is processing data from a single disk file, and it spends most of its time awaiting data from the disk. Since there's only one disk, and the disk can only go so fast, adding more threads would not help in that case.

  •  Tags:  
  • Related