Skip to content

Commit 0fbfdf6

Browse files
authored
Rollup merge of #53024 - matklad:patch-1, r=alexcrichton
Specify reentrancy gurantees of `Once::call_once` I don't think the docs are clear about what happens in the following code ```rust static INIT: Once = ONCE_INIT; INIT.call_once(|| INIT.call_once(|| println!("huh?"))); ``` [Playground](https://play.rust-lang.org/?gist=15dde1f68a6ede263c7250c36977eade&version=stable&mode=debug&edition=2015) Let's "specify" the behavior to make it clear that the current behavior (deadlock I think?) is not a strict guarantee.
2 parents 5ffeaa8 + a2f9aaf commit 0fbfdf6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/libstd/sync/once.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ impl Once {
178178
/// happens-before relation between the closure and code executing after the
179179
/// return).
180180
///
181+
/// If the given closure recusively invokes `call_once` on the same `Once`
182+
/// instance the exact behavior is not specified, allowed outcomes are
183+
/// a panic or a deadlock.
184+
///
181185
/// # Examples
182186
///
183187
/// ```

0 commit comments

Comments
 (0)