about summary refs log tree commit diff
path: root/src/libstd/thread/mod.rs
AgeCommit message (Collapse)AuthorLines
2016-10-10Auto merge of #36341 - sagebind:thread_id, r=alexcrichtonbors-0/+59
Add ThreadId for comparing threads This adds the capability to store and compare threads with the current calling thread via a new struct, `std::thread::ThreadId`. Addresses the need outlined in issue #21507. This avoids the need to add any special checks to the existing thread structs and does not rely on the system to provide an identifier for a thread, since it seems that this approach is unreliable and undesirable. Instead, this simply uses a lazily-created, thread-local `usize` whose value is copied from a global atomic counter. The code should be simple enough that it should be as much reliable as the `#[thread_local]` attribute it uses (however much that is). `ThreadId`s can be compared directly for equality and have copy semantics. Also see these other attempts: - rust-lang/rust#29457 - rust-lang/rust#29448 - rust-lang/rust#29447 And this in the RFC repo: rust-lang/rfcs#1435
2016-10-07Unlock guard before overflow panicStephen M. Coakley-0/+1
2016-10-05Use mutex to guard thread ID counterStephen M. Coakley-30/+8
2016-10-05Generate ID using u64 + atomic spinlockStephen M. Coakley-14/+54
2016-09-30Auto merge of #36339 - brson:emscripten-new, r=alexcrichtonbors-1/+1
Working asmjs and wasm targets This patch set results in a working standard library for the asmjs-unknown-emscripten and wasm32-unknown-emscripten targets. It is based on the work of @badboy and @rschulman. It does a few things: - Updates LLVM with the emscripten [fastcomp](https://github.com/rust-lang/llvm/pull/50) patches, which include the pnacl IR legalizer and the asm.js backend. This patch is thought not to have any significant effect on existing targets. - Teaches rustbuild to correctly link C code with emscripten - Updates gcc-rs to work correctly with emscripten - Teaches rustbuild to run crate tests for emscripten with node - Modifies Thread::new to return an error on emscripten, to facilitate debugging a common failure mode - Modifies libtest to run in single-threaded mode for emscripten - Ignores a host of tests that don't work yet, mostly dealing with threads and I/O - Updates libc with wasm32 definitions (presently the same as asmjs) - Adds a wasm32-unknown-emscripten target that feeds the output of LLVM's asmjs backend through emcc to generate wasm Notes and caveats: - This is only known to work with `--enable-rustbuild`. - The wasm32 target can't be tested correctly yet because of issues in compiletest and limitations in node https://github.com/kripken/emscripten/issues/4542, but hello.rs does seem to work when run on node via the binaryen interpreter - This requires an up to date installation of the emscripten sdk from its incoming branch - Unwinding is very broken - When enabling the emscripten targets jemalloc is disabled for all targets, which results in test failures for the host Next steps are to fix the jemalloc issue, start building the two emscripten targets on the auto builders, then start producing nightlies. https://github.com/rust-lang/rust/issues/36317 tracks work on this. Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36515 Fixes https://github.com/rust-lang/rust/issues/36356
2016-09-30Ignore various entire test modules on emscriptenBrian Anderson-20/+1
2016-09-30Ignore lots and lots of std tests on emscriptenBrian Anderson-0/+19
2016-09-16Update to new macro url syntaxGuillaume Gomez-1/+1
2016-09-08Fix testsStephen M. Coakley-2/+2
2016-09-07Add ThreadId for comparing threadsStephen M. Coakley-0/+40
2016-09-04Clean up thread-local storage docsAndrew Paseltiner-20/+15
`std` no longer contains an implementation of scoped TLS.
2016-08-30Rollup merge of #35997 - matthew-piziak:thread-current-example, r=GuillaumeGomezGuillaume Gomez-0/+18
add a simple example for `thread::current()` r? @GuillaumeGomez
2016-08-25add a simple example for `thread::current()`Matthew Piziak-0/+18
2016-08-24Use `#[prelude_import]` in `libstd`.Jeffrey Seyfried-6/+0
2016-08-03Add link to replacement functionStefan Schindler-1/+6
2016-08-03Add an example to `std::thread::park_timeout`Stefan Schindler-0/+19
2016-06-28Rollup merge of #34406 - frewsxcv:sleep-ex, r=alexcrichtonGuillaume Gomez-0/+13
Add example for `std::thread::sleep`. None
2016-06-27Add example for `std::thread::sleep`.Corey Farwell-0/+13
2016-06-25Auto merge of #34465 - frewsxcv:builder-name-example, r=GuillaumeGomezbors-0/+15
Add doc example for `std::thread::Builder::name`. None
2016-06-25Auto merge of #34410 - frewsxcv:code-like, r=apasel422bors-4/+4
Parameters in doc comment should be formatted code-like. None
2016-06-25Rollup merge of #34438 - frewsxcv:joinhandle, r=GuillaumeGomezManish Goregaokar-0/+30
Indicate how the `JoinHandle` struct is created. None
2016-06-25Add doc example for `std::thread::Builder::name`.Corey Farwell-0/+15
2016-06-24Add examples in docs for `JoinHandle`.Corey Farwell-0/+24
2016-06-24Use `Option::expect` instead of `unwrap_or_else` with `panic!`.Corey Farwell-3/+3
2016-06-24Indicate how the `JoinHandle` struct is created.Corey Farwell-0/+6
2016-06-22Parameters in doc comment should be formatted code-like.Corey Farwell-4/+4
2016-06-21Rollup merge of #34371 - frewsxcv:thread-name, r=steveklabnikGuillaume Gomez-0/+31
Add examples for `std::thread::Thread::name`. None
2016-06-19Add examples for `std::thread::Thread::name`.Corey Farwell-0/+31
2016-06-18Add example in docs for `std::thread::panicking`.Corey Farwell-0/+29
2016-05-30std: Clean out old unstable + deprecated APIsAlex Crichton-10/+0
These should all have been deprecated for at least one cycle, so this commit cleans them all out.
2016-05-16Added a big-picture explanation for thread::park() & co.Pyry Kontio-1/+3
2016-05-09rustc: Implement custom panic runtimesAlex Crichton-11/+6
This commit is an implementation of [RFC 1513] which allows applications to alter the behavior of panics at compile time. A new compiler flag, `-C panic`, is added and accepts the values `unwind` or `panic`, with the default being `unwind`. This model affects how code is generated for the local crate, skipping generation of landing pads with `-C panic=abort`. [RFC 1513]: https://github.com/rust-lang/rfcs/blob/master/text/1513-less-unwinding.md Panic implementations are then provided by crates tagged with `#![panic_runtime]` and lazily required by crates with `#![needs_panic_runtime]`. The panic strategy (`-C panic` value) of the panic runtime must match the final product, and if the panic strategy is not `abort` then the entire DAG must have the same panic strategy. With the `-C panic=abort` strategy, users can expect a stable method to disable generation of landing pads, improving optimization in niche scenarios, decreasing compile time, and decreasing output binary size. With the `-C panic=unwind` strategy users can expect the existing ability to isolate failure in Rust code from the outside world. Organizationally, this commit dismantles the `sys_common::unwind` module in favor of some bits moving part of it to `libpanic_unwind` and the rest into the `panicking` module in libstd. The custom panic runtime support is pretty similar to the custom allocator support with the only major difference being how the panic runtime is injected (takes the `-C panic` flag into account).
2016-05-02std::thread docs: spawn() returns not a Thread anymoreGeorg Brandl-15/+14
Also move the "Thread type" section down a bit, since it is not so important anymore. Fixes: #33321
2016-03-25Fix unsound behaviour with null characters in thread names (issue #32475)David Henningsson-3/+18
Previously, the thread name (&str) was converted to a CString in the new thread, but outside unwind::try, causing a panic to continue into FFI. This patch changes that behaviour, so that the panic instead happens in the parent thread (where panic infrastructure is properly set up), not the new thread. This could potentially be a breaking change for architectures who don't support thread names. Signed-off-by: David Henningsson <diwic@ubuntu.com>
2016-03-22try! -> ?Jorge Aparicio-1/+1
Automated conversion using the untry tool [1] and the following command: ``` $ find -name '*.rs' -type f | xargs untry ``` at the root of the Rust repo. [1]: https://github.com/japaric/untry
2016-03-12std: Clean out deprecated APIsAlex Crichton-34/+0
Removes all unstable and deprecated APIs prior to the 1.8 release. All APIs that are deprecated in the 1.8 release are sticking around for the rest of this cycle. Some notable changes are: * The `dynamic_lib` module was moved into `rustc_back` as the compiler still relies on a few bits and pieces. * The `DebugTuple` formatter now special-cases an empty struct name with only one field to append a trailing comma.
2016-03-04End stdlib module summaries with a full stop.Steve Klabnik-1/+1
Fixes #9447
2016-02-29std: Stabilize APIs for the 1.8 releaseAlex Crichton-0/+1
This commit is the result of the FCPs ending for the 1.8 release cycle for both the libs and the lang suteams. The full list of changes are: Stabilized * `braced_empty_structs` * `augmented_assignments` * `str::encode_utf16` - renamed from `utf16_units` * `str::EncodeUtf16` - renamed from `Utf16Units` * `Ref::map` * `RefMut::map` * `ptr::drop_in_place` * `time::Instant` * `time::SystemTime` * `{Instant,SystemTime}::now` * `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier` * `{Instant,SystemTime}::elapsed` * Various `Add`/`Sub` impls for `Time` and `SystemTime` * `SystemTimeError` * `SystemTimeError::duration` * Various impls for `SystemTimeError` * `UNIX_EPOCH` * `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign` Deprecated * Scoped TLS (the `scoped_thread_local!` macro) * `Ref::filter_map` * `RefMut::filter_map` * `RwLockReadGuard::map` * `RwLockWriteGuard::map` * `Condvar::wait_timeout_with` Closes #27714 Closes #27715 Closes #27746 Closes #27748 Closes #27908 Closes #29866
2015-12-29Fix warnings when compiling stdlib with --testFlorian Hahn-5/+5
2015-12-21std: Use cfg(target_thread_local) in thread_local!Alex Crichton-1/+4
This transitions the standard library's `thread_local!` macro to use the freshly-added and gated `#[cfg(target_thread_local)]` attribute. This greatly simplifies the `#[cfg]` logic in play here, but requires that the standard library expose both the OS and ELF TLS implementation modules as unstable implementation details. The implementation details were shuffled around a bit but end up generally compiling to the same thing. Closes #26581 (this supersedes the need for the option) Closes #27057 (this also starts ignoring the option)
2015-12-09std: Rename thread::catch_panic to panic::recoverAlex Crichton-18/+1
This commit is an implementation of [RFC 1236] and [RFC 1323] which rename the `thread::catch_panic` function to `panic::recover` while also replacing the `Send + 'static` bounds with a new `PanicSafe` bound. [RFC 1236]: https://github.com/rust-lang/rfcs/pull/1236 [RFC 1323]: https://github.com/rust-lang/rfcs/pull/1323 cc #27719
2015-12-04AsRawHandle and IntoRawHandle for JoinHandlePeter Atashian-0/+9
This allows users to get the HANDLE of a spawned thread on Windows Signed-off-by: Peter Atashian <retep998@gmail.com>
2015-11-20Rename #[deprecated] to #[rustc_deprecated]Vadim Petrochenkov-2/+2
2015-11-18Add missing annotations and some testsVadim Petrochenkov-0/+2
2015-11-04Deprecate `_ms` functions that predate the `Duration` APIBen Striegel-0/+2
2015-10-18Clean up thread::spawnarcnmx-23/+16
2015-10-02fix falloutAriel Ben-Yehuda-1/+2
looks like some mix of #18653 and `projection_must_outlive`, but that needs to be investigated further (crater run?)
2015-09-13Auto merge of #28339 - alexcrichton:stabilize-1.4, r=aturonbors-4/+2
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797
2015-09-11std: Internalize almost all of `std::rt`Alex Crichton-3/+4
This commit does some refactoring to make almost all of the `std::rt` private. Specifically, the following items are no longer part of its API: * DEFAULT_ERROR_CODE * backtrace * unwind * args * at_exit * cleanup * heap (this is just alloc::heap) * min_stack * util The module is now tagged as `#[doc(hidden)]` as the only purpose it's serve is an entry point for the `panic!` macro via the `begin_unwind` and `begin_unwind_fmt` reexports.
2015-09-11std: Stabilize/deprecate features for 1.4Alex Crichton-4/+2
The FCP is coming to a close and 1.4 is coming out soon, so this brings in the libs team decision for all library features this cycle. Stabilized APIs: * `<Box<str>>::into_string` * `Arc::downgrade` * `Arc::get_mut` * `Arc::make_mut` * `Arc::try_unwrap` * `Box::from_raw` * `Box::into_raw` * `CStr::to_str` * `CStr::to_string_lossy` * `CString::from_raw` * `CString::into_raw` * `IntoRawFd::into_raw_fd` * `IntoRawFd` * `IntoRawHandle::into_raw_handle` * `IntoRawHandle` * `IntoRawSocket::into_raw_socket` * `IntoRawSocket` * `Rc::downgrade` * `Rc::get_mut` * `Rc::make_mut` * `Rc::try_unwrap` * `Result::expect` * `String::into_boxed_slice` * `TcpSocket::read_timeout` * `TcpSocket::set_read_timeout` * `TcpSocket::set_write_timeout` * `TcpSocket::write_timeout` * `UdpSocket::read_timeout` * `UdpSocket::set_read_timeout` * `UdpSocket::set_write_timeout` * `UdpSocket::write_timeout` * `Vec::append` * `Vec::split_off` * `VecDeque::append` * `VecDeque::retain` * `VecDeque::split_off` * `rc::Weak::upgrade` * `rc::Weak` * `slice::Iter::as_slice` * `slice::IterMut::into_slice` * `str::CharIndices::as_str` * `str::Chars::as_str` * `str::split_at_mut` * `str::split_at` * `sync::Weak::upgrade` * `sync::Weak` * `thread::park_timeout` * `thread::sleep` Deprecated APIs * `BTreeMap::with_b` * `BTreeSet::with_b` * `Option::as_mut_slice` * `Option::as_slice` * `Result::as_mut_slice` * `Result::as_slice` * `f32::from_str_radix` * `f64::from_str_radix` Closes #27277 Closes #27718 Closes #27736 Closes #27764 Closes #27765 Closes #27766 Closes #27767 Closes #27768 Closes #27769 Closes #27771 Closes #27773 Closes #27775 Closes #27776 Closes #27785 Closes #27792 Closes #27795 Closes #27797