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