108 odd tricks for Linux programming-7 (answer gangban_lau)

Source: Internet
Author: User

Gangban_lau: http://blog.csdn.net/gangban_lau/archive/2010/11/10/6000977.aspx

Blog is indeed not a good discussion platform.

for the atomicity or not, we have discussed this topic in shuimu architecture. For more information, see yifanw's speech." on all mordern archiecture, alignment machine word reading and writing must be atomic, which does not need to be questioned. "Of course, after the system architecture changes, this assumption changes, and the entire process will change, so the correctness will not be guaranteed. However, the possibility of this system architecture change is too small, and it will not be possible for a long time in the future. Compatibility will be considered even if it changes.

_ sig_atomic _ is defined as an ordinary int in Linux: typedef int _ sig_atomic_t , everyone complies with the semantics of _ sig_atomic_t. In the future, it will certainly be advantageous. This is without a doubt. From a rigorous point of view, this is indeed the case.

You said, "Maybe there is an implementation that happens that size_t needs two bus access requests to get the complete value .", Because it is defined on the stack, it must be aligned, so it does not happen to need two
The possibility of access. If I cannot convince you of this point, you can check the information. This is all public knowledge. I am a real person, but I want to see practice. You said there may happen to be water on the moon. I cannot prove that there is no water on the moon, because it is impossible to traverse every land on the earth, however, the Moon needs evidence of water. Because no one can present evidence of water on the moon, and most of the evidence proves that there is no water on the moon, it is now accepted that there is no water on the moon, it should be reasonable.

 

For spin lock, I am more experienced and believe in first-hand practices, but the practice environment is always limited and cannot help but fall into limits, in the future, the architecture will change to incompatible. This situation is also possible. Ultra-high concurrency, or slow multi-core situations may exist. I think it will also exist. We should analyze the specific problems. spin lock has application scenarios, for example, if a slow disk is accessed and spin is returned
Lock is obviously not suitable. You should put yourself in the blocking state.


For more informationCodeTo prove the need for manual optimization, because after the-ox optimization is added, the assembly code is hard to understand. This is why I don't need-o. If necessary, I will add it later.

For another example, the recommended struct is the power of 2 (article 2), and the false embedding ing problem is a classic optimization problem. There should be no doubt about this, even in-O3, -O2 cannot be avoided. If you don't believe it, you can experiment with it.

Many times, what we do is easy to use on one platform. porting to another platform may cause problems. optimization is effective on one platform. If another platform is changed, problems may occur, there may even be machine performance improvements, but insteadProgramPerformance has declined, but unfortunately, there is really no way to take care of all possible platforms,Some general things should be written into teaching materials rather than in blogs.Blog is inevitable. Fortunately, my blog has stated: "It does not represent an academic standpoint, but an informal exchange.

So far, I have not been able to fully explain many machine problems. I believe that there will be many people who have this ability to fully explain and want to share it, because the operating system is too complex, there are too many problems involved. Our research can only fix other points and only discuss one point. However, in practice, there are too many reasons that affect performance, such as search engines, to find out all the reasons and conduct in-depth quantitative analysis and explanations, I have a wish to have a deep understanding of the operating system, instruction set, and so on, in the limited future, I can write a book "computing principles" to understand the problem. Unfortunately, I am still studying hard and constantly exploring, but sometimes I will stop, kneel down, expose your shoulders, and place more people on my shoulders to see what fascinated me and explore the principles behind it with me.

 

Finally, we welcome everyone to experiment and question. Practice and question are the prerequisite for progress. Thank you for your question.

Others in this seriesArticle: Http://blog.csdn.net/pennyliang/category/746545.aspx

Related Article

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.