Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 History and significance  





2 See also  





3 References  














Memory model (programming)






Azərbaycanca
فارسی

 

Edit links
 









Article
Talk
 

















Read
Edit
View history
 








Tools
   


Actions  



Read
Edit
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Cite this page
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 
















Appearance
   

 






From Wikipedia, the free encyclopedia
 

(Redirected from Memory model (computing))

In computing, a memory model describes the interactions of threads through memory and their shared use of the data.

History and significance[edit]

A memory model allows a compiler to perform many important optimizations. Compiler optimizations like loop fusion move statements in the program, which can influence the order of read and write operations of potentially shared variables. Changes in the ordering of reads and writes can cause race conditions. Without a memory model, a compiler is not allowed to apply such optimizations to multi-threaded programs in general, or only in special cases. Or for some compilers assume no multi-threaded execution (so better optimized code can be produced), which can lead to optimizations that are incompatible with multi-threading - these can often lead to subtle bugs, that don't show up in early testing.

Modern programming languages like Java therefore implement a memory model. The memory model specifies synchronization barriers that are established via special, well-defined synchronization operations such as acquiring a lock by entering a synchronized block or method. The memory model stipulates that changes to the values of shared variables only need to be made visible to other threads when such a synchronization barrier is reached. Moreover, the entire notion of a race condition is defined over the order of operations with respect to these memory barriers.[1]

These semantics then give optimizing compilers a higher degree of freedom when applying optimizations: the compiler needs to make sure only that the values of (potentially shared) variables at synchronization barriers are guaranteed to be the same in both the optimized and unoptimized code. In particular, reordering statements in a block of code that contains no synchronization barrier is assumed to be safe by the compiler.

Most research in the area of memory models revolves around:

The Java Memory Model was the first attempt to provide a comprehensive threading memory model for a popular programming language.[2] After it was established that threads could not be implemented safely as a library without placing certain restrictions on the implementation and, in particular, that the C and C++ standards (C99 and C++03) lacked necessary restrictions,[3][4] the C++ threading subcommittee set to work on suitable memory model; in 2005, they submitted C working document n1131[5] to get the C Committee on board with their efforts. The final revision of the proposed memory model, C++ n2429,[6] was accepted into the C++ draft standard at the October 2007 meeting in Kona.[7] The memory model was then included in the next C++ and C standards, C++11 and C11.[8][9] The Rust programming language inherited most of C/C++'s memory model. [10]

See also[edit]

References[edit]

  1. ^ Jeremy Manson and Brian Goetz (February 2004). "JSR 133 (Java Memory Model) FAQ". Retrieved 2010-10-18. The Java Memory Model describes what behaviors are legal in multithreaded code, and how threads may interact through memory. It describes the relationship between variables in a program and the low-level details of storing and retrieving them to and from memory or registers in a real computer system. It does this in a way that can be implemented correctly using a wide variety of hardware and a wide variety of compiler optimizations.
  • ^ Goetz, Brian (2004-02-24). "Fixing the Java Memory Model, Part 1". IBM. Retrieved 2008-02-17.
  • ^ Buhr, Peter A. (September 11, 1995). "Are Safe Concurrency Libraries Possible?" (PDF). Communications of the ACM. Retrieved 2015-05-12.
  • ^ Boehm, Hans-J. (November 12, 2004). "Threads Cannot be Implemented as a Library" (PDF). Archived from the original (PDF) on 2017-05-30. Retrieved 2015-05-12.
  • ^ Boehm, Hans; Lea, Doug; Pugh, Bill (2005-08-26). "Implications of C++ Memory Model Discussions on the C Language" (PDF). www.open-std.org. Retrieved 2015-05-12.
  • ^ "WG21/N2429: Concurrency memory model (final revision)". www.open-std.org. 2007-10-05. Retrieved 2015-05-12.
  • ^ "N2480: A Less Formal Explanation of the Proposed C++ Concurrency Memory Model". www.open-std.org. Retrieved 2015-05-12.
  • ^ Alexandrescu, Andrei; Boehm, Hans; Henney, Kevlin; Hutchings, Ben; Lea, Doug; Pugh, Bill (2005-03-04). "Memory Model for Multithreaded C++: Issues" (PDF). Retrieved 2014-04-24. C++ threading libraries are in the awkward situation of specifying (implicitly or explicitly) an extended memory model for C++ in order to specify program execution.We propose integrating a memory model suitable for multithreaded execution into the C++ Standard.
  • ^ Boehm, Hans. "Threads and memory model for C++". Retrieved 2014-04-24. This [link farm] provides information related to the effort to clarify the meaning of multi-threaded C++ programs, and to provide some standard thread-related APIs where those are currently missing.
  • ^ "The Rustonomicon, Atomics". Retrieved 2024-07-08. Rust pretty blatantly just inherits the memory model for atomics from C++20.

  • t
  • e

  • Retrieved from "https://en.wikipedia.org/w/index.php?title=Memory_model_(programming)&oldid=1233362672"

    Categories: 
    Computer memory
    Consistency models
    Compiler construction
    Programming language design
    Run-time systems
    Concurrency (computer science)
    Computer programming stubs
    Hidden category: 
    All stub articles
     



    This page was last edited on 8 July 2024, at 17:51 (UTC).

    Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



    Privacy policy

    About Wikipedia

    Disclaimers

    Contact Wikipedia

    Code of Conduct

    Developers

    Statistics

    Cookie statement

    Mobile view



    Wikimedia Foundation
    Powered by MediaWiki