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
: this unsafe API is unlikely to ever be stabilized in this form
Spawns a new scoped thread, returning a JoinGuard
for it.
The spawn
`spawnmethod does not allow the child and parent threads to share any stack data, since that is not safe in general. However,
scoped` makes it possible to share the parent's stack by forcing
a join before any relevant stack frames are popped:
#![feature(scoped)] use std::thread; let guard = thread::scoped(move || { // some work here }); // do some other work in the meantime let output = guard.join();
The scoped
`scopedfunction doesn't return a
Threaddirectly; instead, it returns a *join guard*. The join guard can be used to explicitly join the child thread (via
join), returning
Result
Panics
Panics if the OS fails to create a thread; use Builder::scoped
to recover from such errors.