Skip to content

Commit 0da8f34

Browse files
committed
Use static in the OnceLock example
1 parent 4d927b4 commit 0da8f34

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

posts/2023-06-01-Rust-1.70.0.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ Two new types have been stabilized for one-time initialization of shared data, `
3232
```rust
3333
use std::sync::OnceLock;
3434

35-
fn main() {
36-
let winner_lock = OnceLock::new();
35+
static WINNER: OnceLock<&str> = OnceLock::new();
3736

37+
fn main() {
3838
let winner = std::thread::scope(|s| {
39-
s.spawn(|| winner_lock.set("thread"));
39+
s.spawn(|| WINNER.set("thread"));
4040

4141
std::thread::yield_now(); // give them a chance...
4242

43-
winner_lock.get_or_init(|| "main")
43+
WINNER.get_or_init(|| "main")
4444
});
4545

4646
println!("{winner} wins!");

0 commit comments

Comments
 (0)