summary refs log tree commit diff
path: root/src/libstd/thread
AgeCommit message (Collapse)AuthorLines
2019-06-20Auto merge of #60341 - mtak-:macos-tlv-workaround, r=alexcrichtonbors-107/+183
macos tlv workaround fixes: #60141 Includes: * remove dead code: `requires_move_before_drop`. This hasn't been needed for a while now (oops I should have removed it in #57655) * redox had a copy of `fast::Key` (not sure why?). That has been removed. * Perform a `read_volatile` on OSX to reduce `tlv_get_addr` calls per `__getit` from (4-2 depending on context) to 1. `tlv_get_addr` is relatively expensive (~1.5ns on my machine). Previously, in contexts where `__getit` was inlined, 4 calls to `tlv_get_addr` were performed per lookup. For some reason when `__getit` is not inlined this is reduced to 2x - and performance improves to match. After this PR, I have only ever seen 1x call to `tlv_get_addr` per `__getit`, and macos now benefits from situations where `__getit` is inlined. I'm not sure if the `read_volatile(&&__KEY)` trick is working around an LLVM bug, or a rustc bug, or neither. r? @alexcrichton
2019-05-15fix wasm unused import in thread local implementationtyler-1/+0
2019-05-15llvm makes good inlining choices with only the #[cold] attributetyler-19/+15
2019-05-15remove trailing whitespacetyler-1/+1
2019-05-15cold was necessary on try_initialize_nodrop to get more straight line asmtyler-0/+1
2019-05-15- remove unnecessary inlinestyler-21/+18
- add comment explaining that the fast::Key data structure was carefully constructed for fast access on OSX - remove inline(never) from the initializer for types where `needs_drop::<T>()` is false
2019-05-15add #[allow(unused)]tyler-0/+1
2019-05-15restructure thread_local! for better codegen (especially on macos)tyler-97/+188
2019-05-15Revert "ensure fast thread local lookups occur once per access on macos"tyler-6/+5
This reverts commit d252f3b77f3b7d4cd59620588f9d026633c05816.
2019-05-15ensure fast thread local lookups occur once per access on macostyler-5/+6
2019-05-15remove dead code: requires_move_before_droptyler-12/+3
2019-05-04Fix intra-doc link resolution failure on re-exporting libstdTaiki Endo-0/+1
2019-04-18Use more realistic example for thread builderAleksey Kladov-1/+1
Stack size of 10 **bytes** does not make any sense: the minimal possible stack size is greater anyway.
2019-04-10Eliminate `FnBox` usages from libstd.CrLF0710-2/+3
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-8/+8
2019-03-27Rollup merge of #59460 - xfix:include-id-in-thread-debug, r=AmanieuJosh Stone-1/+4
Include id in Thread's Debug implementation Since Rust 1.19.0, `id` is a stable method, so there is no reason to not include it in Debug implementation.
2019-03-27Include id in Thread's Debug implementationKonrad Borowski-1/+4
Since Rust 1.19.0, id is a stable method, so there is no reason to not include it in Debug implementation.
2019-03-26Auto merge of #59136 - jethrogb:jb/sgx-std-test, r=sanxiynbors-4/+7
SGX target: fix std unit tests This fixes some tests and some code in the SGX sys implementation to make the `std` unit test suite pass. #59009 must be merged first.
2019-03-25SGX target: fix std unit testsJethro Beekman-4/+7
2019-03-20Add a test for size_of Option<ThreadId>Simon Sapin-1/+7
2019-03-19Make Option<ThreadId> no larger than ThreadId, with NonZeroU64Simon Sapin-3/+4
2019-03-03race condition in thread local storage examplebenaryorg-1/+4
The example had a potential race condition that would still pass the test. If the thread which was supposed to modify it's own thread local was slower than the instruction to modify in the main thread, then the test would pass even in case of a failure. This is would be minor if the child thread was waited for since it check using an `assert_eq` for the same thing, but vice versa. However, if the `assert_eq` failed this would trigger a panic, which is not at all caught by the example since the thread is not waited on. Signed-off-by: benaryorg <binary@benary.org>
2019-03-02Bootstrap compiler update for 1.35 releaseMark Rousskov-6/+2
2019-02-28libstd => 2018Taiki Endo-52/+52
2019-02-12Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnikbors-1/+1
Cosmetic improvements to doc comments This has been factored out from https://github.com/rust-lang/rust/pull/58036 to only include changes to documentation comments (throughout the rustc codebase). r? @steveklabnik Once you're happy with this, maybe we could get it through with r=1, so it doesn't constantly get invalidated? (I'm not sure this will be an issue, but just in case...) Anyway, thanks for your advice so far!
2019-02-11Require a list of features to allow in `allow_internal_unstable`Oliver Scherer-2/+6
2019-02-10tests: doc commentsAlexander Regueiro-1/+1
2019-01-22Print a slightly clearer message when failing to spawn a threadJethro Beekman-1/+1
2019-01-15OSX: fix #57534 registering thread dtors while running thread dtorstyler-7/+1
2018-12-25Remove licensesMark Rousskov-20/+0
2018-12-10Auto merge of #56157 - RalfJung:park, r=nagisabors-5/+22
expand thread::park explanation Cc @carllerche @parched @stjepang
2018-12-07Various minor/cosmetic improvements to codeAlexander Regueiro-6/+6
2018-12-06Change sys::Thread::new to take the thread entry as Box<dyn FnBox() + 'static>̣Jethro Beekman-3/+19
2018-12-03improve wordingRalf Jung-3/+4
2018-11-27Fix small typo in commentMarius Nuennerich-1/+1
2018-11-23make park/unpark example more realisticRalf Jung-4/+15
2018-11-22expand thread::park explanationRalf Jung-1/+6
2018-11-13fix various typos in doc commentsAndy Russell-1/+1
2018-11-06Rollup merge of #55597 - alexcrichton:thread-local-inner, r=KodrAuskennytm-4/+4
std: Enable usage of `thread_local!` through imports The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
2018-11-01std: Enable usage of `thread_local!` through importsAlex Crichton-4/+4
The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
2018-11-01std: Improve codegen size of accessing TLSAlex Crichton-1/+10
Some code in the TLS implementation in libstd stores `Some(val)` into an `&mut Option<T>` (effectively) and then pulls out `&T`, but it currently uses `.unwrap()` which can codegen into a panic even though it can never panic. With sufficient optimizations enabled (like LTO) the compiler can see through this but this commit helps it along in normal mode (`--release` with Cargo by default) to avoid codegen'ing the panic path. This ends up improving the optimized codegen on wasm by ensuring that a call to panic pulling in more file size doesn't stick around.
2018-10-30thread::unpark: Avoid notifying with mutex locked.James Duley-2/+12
This means when the other thread wakes it can continue right away instead of having to wait for the mutex. Also add some comments explaining why the mutex needs to be locked in the first place.
2018-10-28Auto merge of #55043 - oliver-giersch:unchecked_thread_spawning, r=alexcrichtonbors-13/+78
Unchecked thread spawning # Summary Add an unsafe interface for spawning lifetime-unrestricted threads for library authors to build less-contrived, less-hacky safe abstractions on. # Motivation So a few years back scoped threads were entirely removed from the Rust stdlib, the reason being that it was possible to leak the scoped thread's join guards without resorting to unsafe code, which meant the concept was not completely safe, either. Only a maximally-restrictive safe API for thread spawning was kept in the stdlib, that requires `'static` lifetime bounds on both the thread closure and its return type. A number of 3rd party libraries sprung up to offer their implementations for safe scoped threads implementations. These work by essentially hiding the join guards from the user, thus forcing them to join at the end of an (internal) function scope. However, since these libraries have to use the maximally restrictive thread spawning API, they have to resort to some very contrived manipulations and subversions of Rust's type system to basically achieve what this commit does with some minimal restructuring of the current code and exposing a new unsafe function signature for spawning threads without lifetime restrictions. Obviously this is unsafe, but its main use would be to allow library authors to write safe abstractions with and around it. To further illustrate my point, here's a quick summary of the hoops that, for instance `crossbeam`, has to jump through to spawn a lifetime unrestricted thread, all of which would not be necessary if an unsafe API existed as part of the stdlib: 1. Allocate an `Arc<Option<T>>` on the heap where the result with type `T: 'a` will go (in practice requires `Mutex` or `UnsafeCell` as well). 2. Wrap the desired thread closure with lifetime bound `'a` into another closure (also `..: 'a`) that returns `()`, executes the inner closure and writes its result into the pre-allocated `Option<T>`. 3. Box the wrapping closure, cast it to a trait object (`FnBox`) and (unsafely) transmute its lifetime bound from `'a` to `'static`. So while this new `spawn_unchecked` function is certainly not very relevant for general use, since scoped threads are so common I think it makes sense to expose an interface for libraries implementing these to build on. The changes implemented are also very minimal: The current `spawn` function (which internally contains unsafe code) is moved into an unsafe `spawn_unchecked` function, which the safe function then wraps around. # Issues - ~~so far, no documentation for the new function (yet)~~ - the name of the function might be controversial, as `*_unchecked` more commonly indicates that some sort of runtime check is omitted (`unrestricted` may be more fitting) - if accepted, it might make sense to add a freestanding `thread::spawn_unchecked` function similar to the current `thread::spawn` for convenience.
2018-10-18Rollup merge of #54646 - vn971:fix_std_thread_sleep, r=frewsxcvkennytm-10/+14
improve documentation on std::thread::sleep
2018-10-16adds tracking issue numberoliver-giersch-1/+1
2018-10-15Merge pull request #5 from oliver-giersch/masteroliver-giersch-5/+11
sync with upstream
2018-10-15adds feature gate to doc-test (example)oliver-giersch-0/+1
2018-10-15adds missing method call parenthesesoliver-giersch-1/+1
2018-10-15fixes misplaced semicolonoliver-giersch-2/+2
2018-10-15adds doc for `Builder::spawn_unchecked`oliver-giersch-1/+60