2 #![allow(stable_features)]
4 // ignore-emscripten no threads support
6 #![feature(thread_local_try_with)]
9 use std::sync::atomic::{AtomicUsize, Ordering};
11 struct Foo { cnt: usize }
13 thread_local!(static FOO: Foo = Foo::init());
15 static CNT: AtomicUsize = AtomicUsize::new(0);
19 let cnt = CNT.fetch_add(1, Ordering::SeqCst);
30 FOO.with(|foo| assert_eq!(foo.cnt, 0));
32 assert_eq!(self.cnt, 0);
33 if FOO.try_with(|_| ()).is_ok() {
34 panic!("should not be in valid state");