Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mention and use Once::new instead of ONCE_INIT #51056

Merged
merged 2 commits into from
May 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/libstd/sync/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,17 @@ use thread::{self, Thread};
/// A synchronization primitive which can be used to run a one-time global
/// initialization. Useful for one-time initialization for FFI or related
/// functionality. This type can only be constructed with the [`ONCE_INIT`]
/// value.
/// value or the equivalent [`Once::new`] constructor.
///
/// [`ONCE_INIT`]: constant.ONCE_INIT.html
/// [`Once::new`]: struct.Once.html#method.new
///
/// # Examples
///
/// ```
/// use std::sync::{Once, ONCE_INIT};
/// use std::sync::Once;
///
/// static START: Once = ONCE_INIT;
/// static START: Once = Once::new();
///
/// START.call_once(|| {
/// // run initialization here
Expand Down Expand Up @@ -180,10 +181,10 @@ impl Once {
/// # Examples
///
/// ```
/// use std::sync::{Once, ONCE_INIT};
/// use std::sync::Once;
///
/// static mut VAL: usize = 0;
/// static INIT: Once = ONCE_INIT;
/// static INIT: Once = Once::new();
///
/// // Accessing a `static mut` is unsafe much of the time, but if we do so
/// // in a synchronized fashion (e.g. write once or read all) then we're
Expand Down Expand Up @@ -248,10 +249,10 @@ impl Once {
/// ```
/// #![feature(once_poison)]
///
/// use std::sync::{Once, ONCE_INIT};
/// use std::sync::Once;
/// use std::thread;
///
/// static INIT: Once = ONCE_INIT;
/// static INIT: Once = Once::new();
///
/// // poison the once
/// let handle = thread::spawn(|| {
Expand Down Expand Up @@ -431,10 +432,10 @@ impl OnceState {
/// ```
/// #![feature(once_poison)]
///
/// use std::sync::{Once, ONCE_INIT};
/// use std::sync::Once;
/// use std::thread;
///
/// static INIT: Once = ONCE_INIT;
/// static INIT: Once = Once::new();
///
/// // poison the once
/// let handle = thread::spawn(|| {
Expand All @@ -452,9 +453,9 @@ impl OnceState {
/// ```
/// #![feature(once_poison)]
///
/// use std::sync::{Once, ONCE_INIT};
/// use std::sync::Once;
///
/// static INIT: Once = ONCE_INIT;
/// static INIT: Once = Once::new();
///
/// INIT.call_once_force(|state| {
/// assert!(!state.poisoned());
Expand Down