]> git.proxmox.com Git - rustc.git/blob - src/vendor/crossbeam/src/lib.rs
New upstream version 1.20.0+dfsg1
[rustc.git] / src / vendor / crossbeam / src / lib.rs
1 //! Support for concurrent and parallel programming.
2 //!
3 //! This crate is an early work in progress. The focus for the moment is
4 //! concurrency:
5 //!
6 //! - **Non-blocking data structures**. These data structures allow for high
7 //! performance, highly-concurrent access, much superior to wrapping with a
8 //! `Mutex`. Ultimately the goal is to include stacks, queues, deques, bags,
9 //! sets and maps. These live in the `sync` module.
10 //!
11 //! - **Memory management**. Because non-blocking data structures avoid global
12 //! synchronization, it is not easy to tell when internal data can be safely
13 //! freed. The `mem` module provides generic, easy to use, and high-performance
14 //! APIs for managing memory in these cases. These live in the `mem` module.
15 //!
16 //! - **Synchronization**. The standard library provides a few synchronization
17 //! primitives (locks, semaphores, barriers, etc) but this crate seeks to expand
18 //! that set to include more advanced/niche primitives, as well as userspace
19 //! alternatives. These live in the `sync` module.
20 //!
21 //! - **Scoped thread API**. Finally, the crate provides a "scoped" thread API,
22 //! making it possible to spawn threads that share stack data with their
23 //! parents. This functionality is exported at the top-level.
24
25 //#![deny(missing_docs)]
26
27 #![cfg_attr(feature = "nightly",
28 feature(const_fn, repr_simd, optin_builtin_traits))]
29
30 use std::thread;
31
32 pub use scoped::{scope, Scope, ScopedJoinHandle};
33
34 pub mod mem;
35 pub mod sync;
36 mod scoped;
37
38 #[doc(hidden)]
39 trait FnBox {
40 fn call_box(self: Box<Self>);
41 }
42
43 impl<F: FnOnce()> FnBox for F {
44 fn call_box(self: Box<Self>) { (*self)() }
45 }
46
47 /// Like `std::thread::spawn`, but without the closure bounds.
48 pub unsafe fn spawn_unsafe<'a, F>(f: F) -> thread::JoinHandle<()> where F: FnOnce() + Send + 'a {
49 use std::mem;
50
51 let closure: Box<FnBox + 'a> = Box::new(f);
52 let closure: Box<FnBox + Send> = mem::transmute(closure);
53 thread::spawn(move || closure.call_box())
54 }