mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Add test
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//@ run-pass
|
||||
#![allow(stable_features)]
|
||||
//@ needs-threads
|
||||
#![feature(thread_local_try_with)]
|
||||
|
||||
use std::cell::Cell;
|
||||
use std::thread;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Foo {
|
||||
ptr: Cell<*const Foo>,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn touch(&self) {
|
||||
if self.ptr.get().is_null() {
|
||||
self.ptr.set(self);
|
||||
} else {
|
||||
assert!(self.ptr.get() == self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Foo {
|
||||
fn drop(&mut self) {
|
||||
self.touch();
|
||||
}
|
||||
}
|
||||
|
||||
thread_local!(static FOO: Foo = Foo::default());
|
||||
|
||||
fn main() {
|
||||
thread::spawn(|| {
|
||||
FOO.with(|foo| foo.touch());
|
||||
FOO.with(|foo| foo.touch());
|
||||
})
|
||||
.join()
|
||||
.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user