1. 14
  1.  

  2. 1

    Even after reading the first several paragraphs and skimming the rest of this article I still couldn’t tell what a “memory model” is. Does anyone have a decent explanation?

    1. 2

      A memory model is a mathematical model of what happens in a program where there are multiple concurrently running threads of execution which may read and write to shared memory. It specifies what guarantees the synchronisation primitives are required to provide.

      As an application developer, you can use it to reason precisely about what guarantees you’re supposed to be getting from the system by reasoning about the code you wrote and what primitives you used, without having to reason about their internal implementations.

      As a system implementer, it gives you a semantics to implement so you can try to do that with the absolute minimum amount of synchronisation that will possibly suffice. So long as the result is that programs’ observable behaviour meets the spec, you can do whatever.

      AFAIK the first good example that was widely used was the Java Memory Model. It’s also a relatively simple and well explained one, so I’d recommend reading about it.

      1. 2

        Fantastic answer! Exactly what I was looking for.

        1. 2

          Thank you. I’m glad to hear it helped.

          1. 2

            I just remember this link, Close encounters of the Java Memory Model kind which really extensively explains the JMM in great detail (and links to some other more introductory text too)

        2. 1

          Memory model. Lobsters has many of them, too.