Skip to content

Commit 22c5e1d

Browse files
committed
Add test
1 parent 9ffbc62 commit 22c5e1d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ run-pass
2+
#![allow(stable_features)]
3+
//@ needs-threads
4+
#![feature(thread_local_try_with)]
5+
6+
use std::cell::Cell;
7+
use std::thread;
8+
9+
#[derive(Default)]
10+
struct Foo {
11+
ptr: Cell<*const Foo>,
12+
}
13+
14+
impl Foo {
15+
fn touch(&self) {
16+
if self.ptr.get().is_null() {
17+
self.ptr.set(self);
18+
} else {
19+
assert!(self.ptr.get() == self);
20+
}
21+
}
22+
}
23+
24+
impl Drop for Foo {
25+
fn drop(&mut self) {
26+
self.touch();
27+
}
28+
}
29+
30+
thread_local!(static FOO: Foo = Foo::default());
31+
32+
fn main() {
33+
thread::spawn(|| {
34+
FOO.with(|foo| foo.touch());
35+
FOO.with(|foo| foo.touch());
36+
})
37+
.join()
38+
.unwrap();
39+
}

0 commit comments

Comments
 (0)