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
36
37
38
39
40
41
42
43
44
use crate::binary::struct_trait::session::Session;
use std::boxed::Box;
use std::error::Error;
use std::marker;
use std::panic;
use std::thread::{Builder, JoinHandle};
#[doc(hidden)]
pub fn fork_with_thread_id<S, P>(p: P) -> (JoinHandle<()>, S::Dual)
where
S: Session + 'static,
P: FnOnce(S) -> Result<(), Box<dyn Error>> + marker::Send + 'static,
{
let (there, here) = Session::new();
let other_thread = Builder::new()
.name(String::from("Thread P"))
.stack_size(32 * 1024 * 1024)
.spawn(move || {
panic::set_hook(Box::new(|_info| {
}));
match p(there) {
Ok(()) => (),
Err(e) => panic!("{}", e.to_string()),
}
})
.unwrap();
(other_thread, here)
}
pub fn fork<S, P>(p: P) -> S::Dual
where
S: Session + 'static,
P: FnOnce(S) -> Result<(), Box<dyn Error>> + marker::Send + 'static,
{
fork_with_thread_id(p).1
}