From cd43591b5b8f72e6899b639c7991ed741c88c251 Mon Sep 17 00:00:00 2001
From: David Holmes Factoring and Class Design
attribute, the change should be done with a "setter" accessor matched to
the simple "getter".
Sometimes variables are accessed concurrently without appropriate
+synchronization context, such as a held mutex or at a safepoint. In such
+cases the variable should be declared volatile
and it
+should NOT be accessed as a normal C++ lvalue. Rather, access should be
+performed via functions from Atomic
, such as
+Atomic::load
, Atomic::store
, etc.
This special formulation makes it more clear to maintainers that the +variable is accessed concurrently in a lock-free manner.
All source files must have a globally unique basename. The build diff --git a/doc/hotspot-style.md b/doc/hotspot-style.md index 0a0089ee4546b..322bdc8458eab 100644 --- a/doc/hotspot-style.md +++ b/doc/hotspot-style.md @@ -135,6 +135,17 @@ lines of code. Name what you must repeat. change should be done with a "setter" accessor matched to the simple "getter". +#### Conventions for Lock-free Code + +Sometimes variables are accessed concurrently without appropriate synchronization +context, such as a held mutex or at a safepoint. In such cases the variable should +be declared `volatile` and it should NOT be accessed as a normal C++ lvalue. Rather, +access should be performed via functions from `Atomic`, such as `Atomic::load`, +`Atomic::store`, etc. + +This special formulation makes it more clear to maintainers that the variable is +accessed concurrently in a lock-free manner. + ### Source Files * All source files must have a globally unique basename. The build