2014-02-07 20:08:32 +01:00
|
|
|
// Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
2013-11-28 23:44:33 -08:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
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
|
|
|
// exec-env:RUST_LOG=debug
|
|
|
|
|
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() {
|
2015-02-17 15:24:34 -08: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);
|
2014-12-22 09:04:23 -08:00
|
|
|
}).join().ok().unwrap();
|
2013-11-28 23:44:33 -08:00
|
|
|
}
|