From 6ceb5f4bec83b525c5df409559272f0e10863f6a Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 22 Nov 2017 00:00:01 +0100 Subject: Stabilize spin_loop_hint --- .../src/library-features/hint-core-should-pause.md | 41 ---------------------- .../src/library-features/spin-loop-hint.md | 41 ++++++++++++++++++++++ src/libcore/sync/atomic.rs | 5 ++- 3 files changed, 43 insertions(+), 44 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/hint-core-should-pause.md create mode 100644 src/doc/unstable-book/src/library-features/spin-loop-hint.md (limited to 'src') diff --git a/src/doc/unstable-book/src/library-features/hint-core-should-pause.md b/src/doc/unstable-book/src/library-features/hint-core-should-pause.md deleted file mode 100644 index 05e057be493..00000000000 --- a/src/doc/unstable-book/src/library-features/hint-core-should-pause.md +++ /dev/null @@ -1,41 +0,0 @@ -# `hint_core_should_pause` - -The tracking issue for this feature is: [#41196] - -[#41196]: https://github.com/rust-lang/rust/issues/41196 - ------------------------- - -Many programs have spin loops like the following: - -```rust,no_run -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - } -} -``` - -These programs can be improved in performance like so: - -```rust,no_run -#![feature(hint_core_should_pause)] -use std::sync::atomic; -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - atomic::hint_core_should_pause(); - } -} -``` - -Further improvements could combine `hint_core_should_pause` with -exponential backoff or `std::thread::yield_now`. diff --git a/src/doc/unstable-book/src/library-features/spin-loop-hint.md b/src/doc/unstable-book/src/library-features/spin-loop-hint.md new file mode 100644 index 00000000000..cd33f0c5e02 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/spin-loop-hint.md @@ -0,0 +1,41 @@ +# `spin_loop_hint` + +The tracking issue for this feature is: [#41196] + +[#41196]: https://github.com/rust-lang/rust/issues/41196 + +------------------------ + +Many programs have spin loops like the following: + +```rust,no_run +use std::sync::atomic::{AtomicBool,Ordering}; + +fn spin_loop(value: &AtomicBool) { + loop { + if value.load(Ordering::Acquire) { + break; + } + } +} +``` + +These programs can be improved in performance like so: + +```rust,no_run +#![feature(spin_loop_hint)] +use std::sync::atomic; +use std::sync::atomic::{AtomicBool,Ordering}; + +fn spin_loop(value: &AtomicBool) { + loop { + if value.load(Ordering::Acquire) { + break; + } + atomic::spin_loop_hint(); + } +} +``` + +Further improvements could combine `spin_loop_hint` with +exponential backoff or `std::thread::yield_now`. diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index b7cf6d778a2..5486cb29266 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -103,9 +103,8 @@ use fmt; /// /// On some platforms this function may not do anything at all. #[inline] -#[unstable(feature = "hint_core_should_pause", issue = "41196")] -pub fn hint_core_should_pause() -{ +#[stable(feature = "spin_loop_hint", since = "1.23.0")] +pub fn spin_loop_hint() { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] unsafe { asm!("pause" ::: "memory" : "volatile"); -- cgit 1.4.1-3-g733a5 From a115fcd1a0c272e1a176e3e341b323b134f23097 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Wed, 22 Nov 2017 11:24:57 +0100 Subject: Remove spin-loop-hint from the unstable book --- .../src/library-features/spin-loop-hint.md | 41 ---------------------- 1 file changed, 41 deletions(-) delete mode 100644 src/doc/unstable-book/src/library-features/spin-loop-hint.md (limited to 'src') diff --git a/src/doc/unstable-book/src/library-features/spin-loop-hint.md b/src/doc/unstable-book/src/library-features/spin-loop-hint.md deleted file mode 100644 index cd33f0c5e02..00000000000 --- a/src/doc/unstable-book/src/library-features/spin-loop-hint.md +++ /dev/null @@ -1,41 +0,0 @@ -# `spin_loop_hint` - -The tracking issue for this feature is: [#41196] - -[#41196]: https://github.com/rust-lang/rust/issues/41196 - ------------------------- - -Many programs have spin loops like the following: - -```rust,no_run -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - } -} -``` - -These programs can be improved in performance like so: - -```rust,no_run -#![feature(spin_loop_hint)] -use std::sync::atomic; -use std::sync::atomic::{AtomicBool,Ordering}; - -fn spin_loop(value: &AtomicBool) { - loop { - if value.load(Ordering::Acquire) { - break; - } - atomic::spin_loop_hint(); - } -} -``` - -Further improvements could combine `spin_loop_hint` with -exponential backoff or `std::thread::yield_now`. -- cgit 1.4.1-3-g733a5 From d5e8b61054018799c09d0e4c7166a6c4f198cbc5 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Mon, 27 Nov 2017 19:24:13 +0100 Subject: Change the stabilization version to 1.24.0 --- src/libcore/sync/atomic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/libcore/sync/atomic.rs b/src/libcore/sync/atomic.rs index 5486cb29266..8a261b8f077 100644 --- a/src/libcore/sync/atomic.rs +++ b/src/libcore/sync/atomic.rs @@ -103,7 +103,7 @@ use fmt; /// /// On some platforms this function may not do anything at all. #[inline] -#[stable(feature = "spin_loop_hint", since = "1.23.0")] +#[stable(feature = "spin_loop_hint", since = "1.24.0")] pub fn spin_loop_hint() { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] unsafe { -- cgit 1.4.1-3-g733a5