Function std::thread::scoped [-] [+] [src]

pub fn scoped<'a, T, F>(f: F) -> JoinGuard<'a, T> where T: Send + 'a, F: FnOnce() -> T, F: Send + 'a
Unstable

: memory unsafe if destructor is avoided, see #24292

Spawns a new scoped thread, returning a JoinGuard for it.

The join guard can be used to explicitly join the child thread (via join), returning Result<T>, or it will implicitly join the child upon being dropped. Because the child thread may refer to data on the current thread's stack (hence the "scoped" name), it cannot be detached; it must be joined before the relevant stack frame is popped. See the module documentation for additional details.

Panics

Panics if the OS fails to create a thread; use Builder::scoped to recover from such errors.