Skip to content

Document the memory model guaranteed by dotnet/runtime runtimes #63474

@stephentoub

Description

@stephentoub

We routinely run into questions about the coreclr / mono memory models and what model modern .NET code should be targeting.

ECMA specifies a memory model:
http://www.ecma-international.org/publications/standards/Ecma-335.htm
but it's mostly weaker than what's actually supported by the runtimes.

Joe Duffy wrote down a rough sketch of the model from the .NET Framework 2.0 days:
http://joeduffyblog.com/2007/11/10/clr-20-memory-model/
but that was a long time ago, and unofficial.

Igor Ostrovsky wrote two very nice articles about the memory model:
https://docs.microsoft.com/en-us/archive/msdn-magazine/2012/december/csharp-the-csharp-memory-model-in-theory-and-practice
https://docs.microsoft.com/en-us/archive/msdn-magazine/2013/january/csharp-the-csharp-memory-model-in-theory-and-practice-part-2
but that's also from a decade ago, and things have evolved.

We should:

  1. Document the model we want developers to actually code to; that includes code generated by the C# compiler (e.g. it currently doesn't use volatile when caching things like delegates for lambdas into fields). This could be in the Book of the Runtime (BOTR), on docs.microsoft.com, somewhere we can refer to as an official stance.
  2. Fix up code in the repo to respect that model, removing volatile where it's no longer necessary and adding it where it is to conform.

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMImemory modelissues associated with memory model

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions