Thread with 5 posts
jump to expanded posta friend asked me about concurrency in Rust and honest to god, I had never done it before, I only just now looked at the Rust manual, and I managed to write something perfectly correct and safe and really simple, first try
Rust really is the future of systems programming huh. fearless, incredibly easy concurrencyβ¦
like, this is a thread-safe one-time-set global flag:
use std::sync::OnceLock;
static VERBOSE: OnceLock<bool> = OnceLock::new();
fn set_verbose_once(value: bool) {
VERBOSE.set(value).unwrap()
}
fn get_verbose() -> bool {
VERBOSE.get().copied().unwrap()
}
@hikari Ahhh. std::sync::OnceLock == once_cell::sync::OnceCell
(and core::cell::OnceCell == once_cell::unsync::OnceCell)
@cr1901 yup!! i was amazed that the non-thread-local version of the code was actually simpler