/// Spawns a new thread, returning a `JoinHandle` for it.
Spawns a new thread, returning a `JoinHandle` for it.
Spawns a new thread returning a ` JoinHandle ` for it .
pub fn spawn<T, F>(f: F) -> JoinHandle<T>
    where F: FnOnce() -> T + Send + 'static, T: Send + 'static
{
    let comp_res = CompResult(Arc::new(UnsafeCell::new(None)));
    let comp_res_for_closure = comp_res.clone();
    let runnable = move || {
        // TODO: here you theoretically can handle panics
        unsafe {
            *comp_res_for_closure.0.get() = Some(f());
        }
    };
    JoinHandle {
        thread: spawn_runnable(runnable),
        result: comp_res,
    }
}
pub fn spawn < T , F > ( f : F ) -> JoinHandle < T > where F : FnOnce ( ) -> T + Send + ' static , T : Send + ' static { let comp_res = CompResult ( Arc :: new ( UnsafeCell :: new ( None ) ) ) ; let comp_res_for_closure = comp_res . clone ( ) ; let runnable = move | | { // TODO: here you theoretically can handle panics unsafe { * comp_res_for_closure . 0 . get ( ) = Some ( f ( ) ) ; } } ; JoinHandle { thread : spawn_runnable ( runnable ) , result : comp_res , } }
Spawns a new thread, returning a `JoinHandle` for it.
Spawns a new thread returning a ` JoinHandle ` for it .
f
F