Description
RFC #888 introduced single-threaded (i.e., compiler-only) memory fence intrinsics, and was implemented in #24833.
The RFC explicitly does not add safe wrappers for these new barriers, and states
The existing fence intrinsics are exported in libstd with safe wrappers, but this design does not export safe wrappers for the new intrinsics. The existing fence functions will still perform correctly if used where a single-threaded fence is called for, but with a slight reduction in efficiency. Not exposing these new intrinsics through a safe wrapper reduces the possibility for confusion on which fences are appropriate in a given situation, while still providing the capability for users to opt in to a single-threaded fence when appropriate.
While the argument is sound, authors of low-level concurrency libraries are often very concerned about the performance overhead of full-blown memory fences when a simple compiler barrier will do. The current design requires authors of such libraries to either require a nightly compiler (to use intrinsics), or to fall back to the old
asm!("" ::: "memory" : "volatile")
workaround (which for the time being also requires nightly due to feature(asm)
).
I propose adding in a safe wrapper around these compiler barrier intrinsics alongside fence
after all, with name and documentation that clearly indicates how that function differs from what fence
provides. PR incoming shortly.