Knowledge Point sorting

Source: Internet
Author: User

 

About hyper-threading

CPU hyper-threading simply means that when the cache miss of a thread needs to perform the memory access operation, the CPU will wait during the memory access, and then switch to another thread for execution to avoid wasting CPU resources. Memory Access is slow, and the hyper-threading switching design is fast. It is claimed that only one CPU cycle is required.

Why is hyper-threading so fast? Normal thread switching is slow because multiple threads use one thing, such as registers. When a normal thread is switched, the value of one thread must be switched to the value of another thread. Hyper-threading is independent of many things (everything that can be seen by software is independent of every hyper-threading, something that cannot be seen by software, such as caching (hardware-only things, the software cannot be controlled.) whether the design is independent is only known by the CPU designer .), Therefore, hyper-threading switching is fast. You can use another hyper-threading tool without switching the internal data of the register.

C language keyword volatile

The compiler will optimize the compilation of the Code. According to the code context, if the value of a variable is not changed, the value in the register will be directly used next time without memory access.

However, if two processes share one memory, process a changes, process B reads, and process B, they may not be able to read the correct data until they use the values in the register.

In this case, you need to add the volatile keyword when writing the code, telling the compiler not to optimize it, directly accessing the memory instead of taking the register value.

But access to memory is not necessarily a real access to the memory. It is possible that the access value is directly from the cache, And the cache cannot be controlled by the software (the Code cannot be specified to read in the memory or in the cache ), it is controlled by hardware.

Do not think that volatile will be forced to read from the memory, but tell the compiler not to optimize it into a read register, but to access the memory, but to access the memory or cache, it's about the running hardware.

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.