diff --git a/reactive/src/runtime.rs b/reactive/src/runtime.rs index e9cebe5e..c86f5b0a 100644 --- a/reactive/src/runtime.rs +++ b/reactive/src/runtime.rs @@ -3,6 +3,7 @@ use std::{ cell::{Cell, RefCell}, collections::{HashMap, HashSet}, rc::Rc, + sync::atomic::{AtomicBool, Ordering}, }; use smallvec::SmallVec; @@ -13,8 +14,14 @@ use crate::{ signal::Signal, }; +static CREATED: AtomicBool = AtomicBool::new(false); thread_local! { - pub(crate) static RUNTIME: Runtime = Runtime::new(); + pub(crate) static RUNTIME: Runtime = { + if CREATED.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst).is_err() { + panic!("RUNTIME must only be created once. You are probably using signals from multiple threads. All signals need to be accessed exclusively from the main thread."); + } + Runtime::new() + }; } /// The internal reactive Runtime which stores all the reactive system states in a