Memory Reordering/memory model and its impact on. Net

Source: Internet
Author: User

As for the memory model, this is a really bad topic to talk about. Just came in contact five or six years ago. NET, all the way Daniel began to discuss. I remember the time when I read those words and thoughts with a very respectful heart. After that, often back to reread those words, more feel a lot of harvest. But Daniel often speaks quite simply, so despite the number of reads, most of them become the victims of time and bad memory forgotten. So recently determined to write such a blog, summed up the ideas of heroes, gathered in recent years of the conclusion, plus the author a little insignificant harvest, to ensure accurate and informative, Hope illustrated. Programmers help programmers and everyone else. is for the preface.

Do not know as a programmer you have not thought, if the CPU is not in accordance with your program to write the order (programming orders) to execute, the result will be what? If you have not been aware of this before, you may be more shocked. But after entering the multi-core multiprocessor era, this is the fact that the CPU adjusts the order in which the instructions are executed and executes the instructions in the order of Processer. This is an important measure to improve the efficiency of CPU execution.

Except for a handful of people like. NET Framework designers have encountered this problem very early on, leaving aside the C++/java programmers don't talk, I guess a lot. NET programmer first realized this problem, should be when double-check encountered the implementation of a single example model:

Imperfect Singleton Implement

1.  public class Singleton
2. {
3.       private static object syncRoot = new object();
4.       private Singleton instance;
5.
6.      private  Singleton() { }
7.
8.      public Singleton  Instance
9.     {
10.          get
11.          {
12.              if (instance == null)
13.             {
14.                   lock (syncRoot)
15.                 {
16.                       if (instance == null)
17.                     {
18.                           instance = new Singleton ();
19.                     }
20.                  }
21.             }
22.
23.              return instance;
24.          }
25.     }
26. }

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.