Skip to content

Commit aeb2028

Browse files
authored
Rollup merge of rust-lang#53022 - RalfJung:volatile, r=alexcrichton
volatile operations docs: clarify that this does not help wrt. concurrency Triggered by rust-lang#52391. Cc @stjepang @Amanieu Should the intrinsics themselves also get more documentation? They generally do not seem to have much of that.
2 parents 7a23b5d + 71460d4 commit aeb2028

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/libcore/ptr.rs

+30
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
448448
/// `write_bytes`, or `copy`). Note that `*src = foo` counts as a use
449449
/// because it will attempt to drop the value previously at `*src`.
450450
///
451+
/// Just like in C, whether an operation is volatile has no bearing whatsoever
452+
/// on questions involving concurrent access from multiple threads. Volatile
453+
/// accesses behave exactly like non-atomic accesses in that regard. In particular,
454+
/// a race between a `read_volatile` and any write operation to the same location
455+
/// is undefined behavior.
456+
///
451457
/// # Examples
452458
///
453459
/// Basic usage:
@@ -498,6 +504,12 @@ pub unsafe fn read_volatile<T>(src: *const T) -> T {
498504
/// This is appropriate for initializing uninitialized memory, or overwriting
499505
/// memory that has previously been `read` from.
500506
///
507+
/// Just like in C, whether an operation is volatile has no bearing whatsoever
508+
/// on questions involving concurrent access from multiple threads. Volatile
509+
/// accesses behave exactly like non-atomic accesses in that regard. In particular,
510+
/// a race between a `write_volatile` and any other operation (reading or writing)
511+
/// on the same location is undefined behavior.
512+
///
501513
/// # Examples
502514
///
503515
/// Basic usage:
@@ -1057,6 +1069,12 @@ impl<T: ?Sized> *const T {
10571069
/// `write_bytes`, or `copy`). Note that `*self = foo` counts as a use
10581070
/// because it will attempt to drop the value previously at `*self`.
10591071
///
1072+
/// Just like in C, whether an operation is volatile has no bearing whatsoever
1073+
/// on questions involving concurrent access from multiple threads. Volatile
1074+
/// accesses behave exactly like non-atomic accesses in that regard. In particular,
1075+
/// a race between a `read_volatile` and any write operation to the same location
1076+
/// is undefined behavior.
1077+
///
10601078
/// # Examples
10611079
///
10621080
/// Basic usage:
@@ -1790,6 +1808,12 @@ impl<T: ?Sized> *mut T {
17901808
/// `write_bytes`, or `copy`). Note that `*self = foo` counts as a use
17911809
/// because it will attempt to drop the value previously at `*self`.
17921810
///
1811+
/// Just like in C, whether an operation is volatile has no bearing whatsoever
1812+
/// on questions involving concurrent access from multiple threads. Volatile
1813+
/// accesses behave exactly like non-atomic accesses in that regard. In particular,
1814+
/// a race between a `read_volatile` and any write operation to the same location
1815+
/// is undefined behavior.
1816+
///
17931817
/// # Examples
17941818
///
17951819
/// Basic usage:
@@ -2105,6 +2129,12 @@ impl<T: ?Sized> *mut T {
21052129
/// This is appropriate for initializing uninitialized memory, or overwriting
21062130
/// memory that has previously been `read` from.
21072131
///
2132+
/// Just like in C, whether an operation is volatile has no bearing whatsoever
2133+
/// on questions involving concurrent access from multiple threads. Volatile
2134+
/// accesses behave exactly like non-atomic accesses in that regard. In particular,
2135+
/// a race between a `write_volatile` and any other operation (reading or writing)
2136+
/// on the same location is undefined behavior.
2137+
///
21082138
/// # Examples
21092139
///
21102140
/// Basic usage:

0 commit comments

Comments
 (0)