Skip to content

Commit

Permalink
sync: document that Mutex::const_new() is not instrumented
Browse files Browse the repository at this point in the history
The mutex created by `Mutex::const_new()` does not contain the tracing
instrumentation that drives `tokio-console`.

This change adds documentation to inform the user of this.
  • Loading branch information
hds committed Sep 12, 2023
1 parent 65e7715 commit c4449e8
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tokio/src/sync/mutex.rs
Expand Up @@ -371,13 +371,21 @@ impl<T: ?Sized> Mutex<T> {

/// Creates a new lock in an unlocked state ready for use.
///
/// When using the `tracing` [unstable feature], a `Mutex` created with
/// `const_new` will not be instrumented. As such, it will not be visible
/// in [`tokio-console`] Instead, [`Mutex::new`] should be used to create
/// an instrumented object if that is needed.
///
/// # Examples
///
/// ```
/// use tokio::sync::Mutex;
///
/// static LOCK: Mutex<i32> = Mutex::const_new(5);
/// ```
///
/// [`tokio-console`]: https://github.com/tokio-rs/console
/// [unstable feature]: crate#unstable-features
#[cfg(not(all(loom, test)))]
pub const fn const_new(t: T) -> Self
where
Expand Down

0 comments on commit c4449e8

Please sign in to comment.