Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reinier Maas
GHC
Commits
856b5e75
Commit
856b5e75
authored
1 year ago
by
Ben Gamari
Committed by
Marge Bot
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Add Note [C11 memory model]
parent
55c65dbc
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
rts/include/stg/SMP.h
+42
-1
42 additions, 1 deletion
rts/include/stg/SMP.h
with
42 additions
and
1 deletion
rts/include/stg/SMP.h
+
42
−
1
View file @
856b5e75
...
...
@@ -110,6 +110,47 @@ EXTERN_INLINE void busy_wait_nop(void);
#endif // !IN_STG_CODE
/*
* Note [C11 memory model]
* ~~~~~~~~~~~~~~~~~~~~~~~
* When it comes to memory, real multiprocessors provide a wide range of
* concurrency semantics due to out-of-order execution and caching.
* To provide consistent reasoning across architectures, GHC relies the C11
* memory model. Not only does this provide a well-studied, fairly
* easy-to-understand conceptual model, but the C11 memory model gives us
* access to a number of tools which help us verify the compiler (see Note
* [ThreadSanitizer] in rts/include/rts/TSANUtils.h).
*
* Under the C11 model, each processor can be imagined to have a potentially
* out-of-date view onto the system's memory, which can be manipulated with two
* classes of memory operations:
*
* - non-atomic operations (e.g. loads and stores) operate strictly on the
* processor's local view of memory and consequently may not be visible
* from other processors.
*
* - atomic operations (e.g. load, store, fetch-and-{add,subtract,and,or},
* exchange, and compare-and-swap) parametrized by ordering semantics.
*
* The ordering semantics of an operation (acquire, release, or sequentially
* consistent) will determine the amount of synchronization the operation
* requires.
*
* A processor may synchronize its
* view of memory with that of another processor by performing an atomic
* memory operation.
*
* While non-atomic operations can be thought of as operating on a local
*
* See also:
*
* - The C11 standard, ISO/IEC 14882 2011.
*
* - Boehm, Adve. "Foundations of the C++ Concurrency Memory Model."
* PLDI '08.
*
* - Batty, Owens, Sarkar, Sewall, Weber. "Mathematizing C++ Concurrency."
* POPL '11.
*
* Note [Heap memory barriers]
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Machines with weak memory ordering semantics have consequences for how
...
...
@@ -124,7 +165,7 @@ EXTERN_INLINE void busy_wait_nop(void);
* in terms of an abstract memory model and let the compiler (GHC and the
* system's C compiler) worry about what barriers are needed to realize the
* requested semantics on the target system. GHC relies on the widely used C11
* memory model for this.
* memory model for this
; see Note [C11 memory model] for a brief introduction
.
*
* Also note that the majority of this Note are only concerned with mutation
* by the mutator. The GC is free to change nearly any field (which is
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment