I think, since everyone is looking at the special use of multi-threading, presumably should have a certain understanding of multithreading, next, I would like to explain how to use single-process multithreading full CPU bar.
First, tell us a common sense:
In a single-core environment, an empty loop can result in a 100% CPU share. In a dual-core environment, the total CPU share is about 50%, the Quad core is about 25%, then the next step is to create 4 threads to fill up the CPU!
The code looks like this: (just looking at the thread library class in the C++11 standard.) )
#include <iostream>#include<thread>#include<mutex>using namespacestd;voidRere () { while(1){}}intMain () {intA; Thread T1 (rere); Thread T2 (rere); thread t3 (rere); thread t4 (rere); T1.join (); T2.join (); Std::cout<<"Main thread!"<<Endl; return 0;}
View Code
Test results:
Forget it, it's not good.
A lot of harvest today, ha ha ha haha.
The problem of how multithreading fills the CPU!