pub enum Races {
Off,
Metadata,
Pointer,
}Expand description
Whether pointer races are watched, from -fsafety-races=.
Design: spec/safe-memory/09-type-init-and-races.md section 9.5, which is document 03’s C1
through C4 and is judgement J9 of document 04 section 4.4. A thread counts its own metadata
stores, a store through a pointer shaped slot leaves that count in the epoch plane, and an
access that finds a count from another thread which nothing it has done orders is a race that
really happened in the interleaving that really ran.
A flag rather than a default, and the reason is not cost. It is that this is the one plane in
the compiler where instrumentation nobody wrote costs a false report instead of a missed one.
Every ordering the monitor has was carried by a synchronization edge somebody interposed, so two
threads that an edge nobody saw really did join look exactly like two threads nothing joined.
The edges that are calls are interposed already, and the ordering that is not a call at all is
emitted by this pass beside the checks: an atomic that publishes gets a meta_release in front
of it and one that takes gets a meta_acquire after it. A bare atomic_thread_fence gets the
same pair with no key, since it orders against every thread rather than against an object and so
has no address an edge could be keyed on, and the runtime holds one clock for every fence in the
program rather than a table.
Which is also why the default stays Races::Off after the flag works. Turning it on is a
decision about a program, not about a build.
Variants§
Off
-fsafety-races=off. Nothing records into the epoch plane and nothing asks it anything.
Metadata
-fsafety-races=metadata. The classes that produce a wrong pointer rather than a wrong
number, which section 9.5 lists as C1, C3 and C4, and which Tier E carries.
Pointer
-fsafety-races=pointer. The same, and C2 as well, which is a race on a pointer word
reported in its own right rather than only used to decide one of the other three.
Implementations§
Source§impl Races
impl Races
Sourcepub const fn as_str(self) -> &'static str
pub const fn as_str(self) -> &'static str
The spelling this is asked for by, without the flag in front of it.
Sourcepub const fn records(self) -> bool
pub const fn records(self) -> bool
Whether a store through a pointer shaped slot records which thread made it, and asks first whether another thread got there with nothing in between.
Both of the modes that are not off. Every class section 9.5 lists is decided by comparing against a stamp a store left behind, so both of them record, and the question a store puts is C3, the metadata race, which both of them report.
Sourcepub const fn reads(self) -> bool
pub const fn reads(self) -> bool
Whether a load of a pointer asks the same question, which is where the two modes differ.
C2 of section 9.5, the general pointer word race, which the section lists apart from the
other three because it is the class reported in its own right rather than used to decide one
of them. Tier E carries metadata and not this, so a build that wants every race a load can
see has to ask for it by name.