Commit Graph

341 Commits

Author SHA1 Message Date
Vadim Petrochenkov 42a317a1cd Remove run-pass test suites 2019-07-27 18:56:17 +03:00
bors 3c805ce183 Auto merge of #60341 - mtak-:macos-tlv-workaround, r=alexcrichton
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-06-20 02:36:49 +00:00
tyler 2c3796172b fix wasm unused import in thread local implementation 2019-05-15 14:35:24 -07:00
tyler 9289d03c9d llvm makes good inlining choices with only the #[cold] attribute 2019-05-15 07:30:34 -07:00
tyler 2b3642b95b remove trailing whitespace 2019-05-15 07:30:34 -07:00
tyler c3241d0ba0 cold was necessary on try_initialize_nodrop to get more straight line asm 2019-05-15 07:30:34 -07:00
tyler 1a7f774914 - remove unnecessary inlines
- 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-15 07:30:34 -07:00
tyler 060d8bb6b0 add #[allow(unused)] 2019-05-15 07:30:34 -07:00
tyler dfe51a7249 restructure thread_local! for better codegen (especially on macos) 2019-05-15 07:30:33 -07:00
tyler 7acfb99adc Revert "ensure fast thread local lookups occur once per access on macos"
This reverts commit d252f3b77f3b7d4cd59620588f9d026633c05816.
2019-05-15 07:30:33 -07:00
tyler 430a091cd8 ensure fast thread local lookups occur once per access on macos 2019-05-15 07:30:33 -07:00
tyler 48e3da6d59 remove dead code: requires_move_before_drop 2019-05-15 07:30:33 -07:00
Taiki Endo ccb9dac5ed Fix intra-doc link resolution failure on re-exporting libstd 2019-05-04 23:48:57 +09:00
Aleksey Kladov be69785ea2 Use more realistic example for thread builder
Stack size of 10 **bytes** does not make any sense: the minimal possible stack size is greater anyway.
2019-04-18 14:58:38 +03:00
CrLF0710 6635fbed4c Eliminate FnBox usages from libstd. 2019-04-10 09:40:44 +08:00
Mazdak Farrokhzad 379c380a60 libstd: deny(elided_lifetimes_in_paths) 2019-03-31 12:56:51 +02:00
Josh Stone a2c4562690 Rollup merge of #59460 - xfix:include-id-in-thread-debug, r=Amanieu
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-27 18:15:44 -07:00
Konrad Borowski ba21e0b368 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-27 12:28:17 +01:00
bors 54479c624c Auto merge of #59136 - jethrogb:jb/sgx-std-test, r=sanxiyn
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-26 01:48:34 +00:00
Jethro Beekman f229422cc1 SGX target: fix std unit tests 2019-03-25 11:31:19 -07:00
Simon Sapin c1d9191fa5 Add a test for size_of Option<ThreadId> 2019-03-20 19:04:38 +01:00
Simon Sapin 8cf720bd19 Make Option<ThreadId> no larger than ThreadId, with NonZeroU64 2019-03-19 14:00:13 +01:00
benaryorg 2293d2260a race condition in thread local storage example
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-03 20:53:50 +01:00
Mark Rousskov 2870015b7b Bootstrap compiler update for 1.35 release 2019-03-02 09:05:34 -07:00
Taiki Endo 93b6d9e086 libstd => 2018 2019-02-28 04:06:15 +09:00
bors b244f61b77 Auto merge of #58341 - alexreg:cosmetic-2-doc-comments, r=steveklabnik
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-12 19:09:24 +00:00
Oliver Scherer d3c212c552 Require a list of features to allow in allow_internal_unstable 2019-02-11 15:08:16 +01:00
Alexander Regueiro b87363e763 tests: doc comments 2019-02-10 23:42:32 +00:00
Jethro Beekman 2ec0e85305 Print a slightly clearer message when failing to spawn a thread 2019-01-22 18:55:12 +05:30
tyler 1a51bb8174 OSX: fix #57534 registering thread dtors while running thread dtors 2019-01-15 20:09:06 -08:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
bors 3a75e80557 Auto merge of #56157 - RalfJung:park, r=nagisa
expand thread::park explanation

Cc @carllerche @parched @stjepang
2018-12-10 12:19:47 +00:00
Alexander Regueiro ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Jethro Beekman c559216ad0 Change sys::Thread::new to take the thread entry as Box<dyn FnBox() + 'static>̣ 2018-12-06 20:37:15 +05:30
Ralf Jung 76cd8f0594 improve wording 2018-12-03 15:14:31 +01:00
Marius Nuennerich 73b656bbb3 Fix small typo in comment 2018-11-27 18:57:55 +01:00
Ralf Jung 7b6ad7a960 make park/unpark example more realistic 2018-11-23 11:04:16 +01:00
Ralf Jung 2d46ae7c37 expand thread::park explanation 2018-11-22 10:54:04 +01:00
Andy Russell 4e35cbb22e fix various typos in doc comments 2018-11-13 14:45:31 -05:00
kennytm 462f63e1bb Rollup merge of #55597 - alexcrichton:thread-local-inner, r=KodrAus
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-06 17:08:03 +08:00
Alex Crichton ff5226cd2f 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-01 14:17:39 -07:00
Alex Crichton 0c3d08e967 std: Improve codegen size of accessing TLS
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-11-01 10:46:31 -07:00
James Duley d3e71e4986 thread::unpark: Avoid notifying with mutex locked.
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-30 22:54:35 +00:00
bors bcb05a0ab2 Auto merge of #55043 - oliver-giersch:unchecked_thread_spawning, r=alexcrichton
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-28 21:34:12 +00:00
kennytm e4ac447851 Rollup merge of #54646 - vn971:fix_std_thread_sleep, r=frewsxcv
improve documentation on std::thread::sleep
2018-10-18 12:54:42 +08:00
oliver-giersch 7849aeddb9 adds tracking issue number 2018-10-16 22:42:14 +02:00
oliver-giersch 30bfdc8720 Merge pull request #5 from oliver-giersch/master
sync with upstream
2018-10-15 14:38:34 +02:00
oliver-giersch ebb9d289db adds feature gate to doc-test (example) 2018-10-15 14:14:17 +02:00
oliver-giersch ee5703cbbc adds missing method call parentheses 2018-10-15 13:47:27 +02:00
oliver-giersch 9d7a83862b fixes misplaced semicolon 2018-10-15 13:22:39 +02:00