2019-07-27 00:54:25 +03:00
|
|
|
// run-pass
|
2014-08-11 16:24:19 -07:00
|
|
|
// ignore-windows
|
2016-02-11 12:34:41 +01:00
|
|
|
// ignore-emscripten no threads support
|
2013-11-28 23:44:33 -08:00
|
|
|
|
2013-12-31 15:46:27 -08:00
|
|
|
use std::cell::Cell;
|
2013-11-28 23:44:33 -08:00
|
|
|
use std::fmt;
|
2015-02-17 15:24:34 -08:00
|
|
|
use std::thread;
|
2013-11-28 23:44:33 -08:00
|
|
|
|
2015-03-25 17:06:52 -07:00
|
|
|
struct Foo(Cell<isize>);
|
2013-11-28 23:44:33 -08:00
|
|
|
|
2015-01-28 08:34:18 -05:00
|
|
|
impl fmt::Debug for Foo {
|
2014-02-05 23:55:13 +11:00
|
|
|
fn fmt(&self, _fmt: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
let Foo(ref f) = *self;
|
2015-06-07 21:00:38 +03:00
|
|
|
assert_eq!(f.get(), 0);
|
2013-12-31 15:46:27 -08:00
|
|
|
f.set(1);
|
2014-01-30 11:56:51 -08:00
|
|
|
Ok(())
|
2013-11-28 23:44:33 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {
|
2020-07-25 18:36:44 +02:00
|
|
|
thread::spawn(move || {
|
2013-12-31 15:46:27 -08:00
|
|
|
let mut f = Foo(Cell::new(0));
|
2014-12-20 00:09:35 -08:00
|
|
|
println!("{:?}", f);
|
2013-11-01 18:06:31 -07:00
|
|
|
let Foo(ref mut f) = f;
|
2015-06-07 21:00:38 +03:00
|
|
|
assert_eq!(f.get(), 1);
|
2020-07-25 18:36:44 +02:00
|
|
|
})
|
|
|
|
.join()
|
|
|
|
.ok()
|
|
|
|
.unwrap();
|
2013-11-28 23:44:33 -08:00
|
|
|
}
|