about summary refs log tree commit diff
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-08-04 14:35:59 +0800
committerGitHub <noreply@github.com>2018-08-04 14:35:59 +0800
commit43410981ae51c0af24c4657e3cc7cd4a01d41a95 (patch)
tree8cefe5f682037d3a4080ce5051aa8585328161b3
parentaeb20284817497a895fee5a22b0013acd0a430e2 (diff)
parenta2f9aaf7a35e673c3b8f0825a07505b0294aa24f (diff)
downloadrust-43410981ae51c0af24c4657e3cc7cd4a01d41a95.tar.gz
rust-43410981ae51c0af24c4657e3cc7cd4a01d41a95.zip
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.
-rw-r--r--src/libstd/sync/once.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/libstd/sync/once.rs b/src/libstd/sync/once.rs
index 10282ecb658..3abc260b458 100644
--- a/src/libstd/sync/once.rs
+++ b/src/libstd/sync/once.rs
@@ -178,6 +178,10 @@ impl Once {
     /// happens-before relation between the closure and code executing after the
     /// return).
     ///
+    /// If the given closure recusively invokes `call_once` on the same `Once`
+    /// instance the exact behavior is not specified, allowed outcomes are
+    /// a panic or a deadlock.
+    ///
     /// # Examples
     ///
     /// ```