mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-27 01:04:03 +00:00
35 lines
705 B
Rust
35 lines
705 B
Rust
//@ run-pass
|
|
//@ needs-threads
|
|
|
|
use std::thread;
|
|
|
|
#[link(name = "rust_test_helpers", kind = "static")]
|
|
extern "C" {
|
|
pub fn rust_dbg_call(
|
|
cb: extern "C" fn(u64) -> u64,
|
|
data: u64,
|
|
) -> u64;
|
|
}
|
|
|
|
extern "C" fn cb(data: u64) -> u64 {
|
|
if data == 1 { data } else { count(data - 1 ) + 1 }
|
|
}
|
|
|
|
fn count(n: u64) -> u64 {
|
|
unsafe {
|
|
println!("n = {}", n);
|
|
rust_dbg_call(cb, n)
|
|
}
|
|
}
|
|
|
|
pub fn main() {
|
|
// Make sure we're on a thread with small Rust stacks (main currently
|
|
// has a large stack)
|
|
thread::spawn(move || {
|
|
let result = count(1000);
|
|
println!("result = {}", result);
|
|
assert_eq!(result, 1000);
|
|
})
|
|
.join().unwrap();
|
|
}
|