1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#[cfg(all(unix, feature = "debug"))]
pub use backtrace_on_stack_overflow;
use std::thread;
#[macro_export]
macro_rules! enable_overflow_stacktrace {
() => {
#[cfg(all(unix, feature = "debug"))]
unsafe {
$crate::spawn::backtrace_on_stack_overflow::enable()
};
};
}
pub fn exec_new_thread<F, T>(run: F) -> T
where
F: FnOnce() -> T + Send + 'static,
T: Send + 'static,
{
enable_overflow_stacktrace!();
if cfg!(windows) || cfg!(feature = "large_thread") {
const STACK_SIZE: usize = 4 * 1024 * 1024;
let child = thread::Builder::new()
.stack_size(STACK_SIZE)
.spawn(run)
.unwrap();
child.join().unwrap()
} else {
run()
}
}