The problem of how multithreading fills the CPU!

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.