Closed . This question needs to be more focused . It is not currently accepting answers.
Memory Models and Concurrency, I understand that a memory model is an abstraction that allows the programmer to reason about the underlying memory system using a Foundations of the C++ Concurrency Memory Model Hans-J. Boehm HP Laboratories Hans.Boehm@hp.com Sarita V. Adve University of Illinois at Urbana-Champaign sadve@cs.uiuc.edu Abstract Currently multi-threaded C or C++ programs combine a single-threaded programming language with a separate threads library. This is not entirely sound [7].
The reason that memory model doesn't apply to single threaded code is that in ST code you execute one statement after another and there is no possibility of mix-up. In multi-threaded code it is possible for an object's value to change without warning to the current thread. The memory model concept lets you ensure that particular statements execute after all other threads have finished updating a value or that a particular statement executes before any other thread reads the object's value.
Memory model (programming), In computing, a memory model describes the interactions of threads through memory and their "WG21/N2429: Concurrency memory model (final revision)". There are two common models for concurrent programming: shared memory and message passing . Shared memory. In the shared memory model of concurrency, concurrent modules interact by reading and writing shared objects in memory.
this is a cite from https://en.wikipedia.org/wiki/Memory_model_(programming)
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.
The compiler can change the order of read and write of variables, and still guarantee the code fragment will run as if the read/writes are done sequentially. however if multi-threading is involved, this can cause problems, as reading/writing of variables, not at the code order, may cause multi-threaded related problems.
examine the following code which is executed by 2 threads, both use the same variables init and value:
static int init = 0;
static int value = 0;
thread_a:
while( !init )
Sleep( 100 );
if ( value == 100 )
do something ...
thread_b:
value = 100;
init = 1;
the compiler may run the code for thread_b in different order (or in parallel) causing init to be set to 1 before value is set to 100. when working with single thread, this has no signifcant, however, when having multiple threads examining this variables, this can cause a problem. and here the memory model comes to solve this problems.
Concurrency Models, split the tasks in different ways, and the threads may communicate and collaborate in different ways. In terms of concurrency, a memory model specifies the constraints on data accesses, and the conditions under which data written by one thread/core/processor becomes visible to another.
What is generally referred to as memory model refers to the interaction of different threads of execution accessing objects. In this sense it is entirely tied to concurrency. It isn’t reall about memory.
There is another important aspect which is referred to as object model and Stan Lippman’s book is an excellent resource for learning about that (it is a bit dated but stays mostly relevant). The object model also doesn’t really talk about how memory is accessed.
The closest to a description of how memory is accessed in general is Ulrich Drepper’s What Every Programmer Should Know About Memory_ . This artivle is about the general view of memory, independent of programming languages. Of course, depending on the object model different programming languages may hide direct interaction with memory.
What is concurrency in programming?, , these situations are encountered: When two processes are assigned to different cores on a machine by the kernel, and both cores execute the process instructions at the same time. The ECOOP 2010 paper below develops a novel principle for reasoning about assembly programs on our previous x86-TSO memory model, uses it to analyze concurrency abstraction implementations of two spinlocks (from Linux), a non-blocking write protocol, the double-checked locking idiom; and java.util.concurrent's Parker.
Java Concurrency / Multithreading Basics, - Multiple parts of the same program running concurrently. The memory model is the crux of the concurrency semantics of shared-memory systems. It denes the possible values that a read operation is allowed to return for any given set of write operations performed by a concurrent program, thereby dening the basic semantics
Reading 17: Concurrency, tions]: Concurrent, distributed, and parallel languages. General Terms Design, Languages. Keywords memory models, sequential consistency, data races,. Concurrent systems can be implemented using different concurrency models. A concurrency model specifies how threads in the the system collaborate to complete the tasks they are are given. Different concurrency models split the tasks in different ways, and the threads may communicate and collaborate in different ways.
[PDF] DRFx: A Simple and Efficient Memory Model for Concurrent , If a thread offers concurrent forward progress guarantee, it will make progress (as defined above) in finite amount of Shared memory and message passing concurrency have different performance characteristics. Typically (although not always), the per-process memory overhead and task switching overhead is lower in a message passing system, but the overhead of message passing is greater than for a procedure call.
Comments Welcome to Stack Overflow. Please read the About and How to Ask pages soon. A question like this, especially when tagged with both c and c++, is simply too broad to be answerable on SO. It would take a lot of explanation; books have been written on the topic. And there are major differences between C and C++, especially in what's actually implemented compared with what the standard says might be implemented by a conforming implementation. Perhaps amazon.co.uk/Inside-Object-Model-Stanley-Lippman/dp/0201834545 @JonathanLeffler I think the answer is the same irrespective of the language. It's a question at a more fundamental level. So I don't think it's broad. The OP probably used the C and C++ tags because they were expecting that those communities would be able to answer the question. The term memory model is used in different ways depending on the context. I think the OP think it's the memory addressing model .