Skip to content

Commit aac2f73

Browse files
committed
Improve comments from #72617, as suggested by RalfJung.
1 parent d462551 commit aac2f73

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/libstd/panicking.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,10 @@ pub mod panic_count {
229229
thread_local! { static LOCAL_PANIC_COUNT: Cell<usize> = Cell::new(0) }
230230

231231
// Sum of panic counts from all threads. The purpose of this is to have
232-
// a fast path in `is_zero` (which is used by `panicking`). Access to
233-
// this variable can be always be done with relaxed ordering because
234-
// it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero,
235-
// `LOCAL_PANIC_COUNT` will be zero.
232+
// a fast path in `is_zero` (which is used by `panicking`). In any particular
233+
// thread, if that thread currently views `GLOBAL_PANIC_COUNT` as being zero,
234+
// then `LOCAL_PANIC_COUNT` in that thread is zero. This invariant holds before
235+
// and after increase and decrease, but not necessarily during their execution.
236236
static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0);
237237

238238
pub fn increase() -> usize {
@@ -263,6 +263,11 @@ pub mod panic_count {
263263
// Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads
264264
// (including the current one) will have `LOCAL_PANIC_COUNT`
265265
// equal to zero, so TLS access can be avoided.
266+
//
267+
// A relaxed atomic load is equivalent to a normal aligned memory read
268+
// (e.g., a `mov` instruction in x86), while a TLS access might require
269+
// calling a non-inlinable function (such as `__tls_get_addr` when using
270+
// the GD TLS model).
266271
true
267272
} else {
268273
is_zero_slow_path()

0 commit comments

Comments
 (0)