Commit graph

201 commits

Author SHA1 Message Date
ljedrz
560d8079ec Deny bare trait objects in src/libstd. 2018-07-10 20:35:36 +02:00
bors
2eb6969c6a Auto merge of #51290 - Pslydhh:master, r=alexcrichton
park/park_timeout: prohibit spurious wakeups in next park

<pre><code>
// The implementation currently uses the trivial strategy of a Mutex+Condvar
// with wakeup flag, which does not actually allow spurious wakeups.
</pre></code>

Because does not actually allow spurious wakeups.
so we have let thread.inner.cvar.wait(m) in the loop to prohibit spurious wakeups.
but if notified after we locked, this notification doesn't be consumed, it return, the next park will consume this notification...this is also 'spurious wakeup' case, 'one unpark() wakeups two  park()'.

We should improve this situation:
`thread.inner.state.store(EMPTY, SeqCst);`
2018-06-29 07:34:13 +00:00
NODA, Kai
b81da27862 libstd: add an RAII utility for sys_common::mutex::Mutex
Signed-off-by: NODA, Kai <nodakai@gmail.com>
2018-06-17 15:18:32 +08:00
Pslydhh
b352d2d167
removes tabs 2018-06-02 15:59:54 +08:00
Pslydhh
151e41ff0c
remove trailing whitespace
remove trailing whitespace
2018-06-02 15:36:23 +08:00
Pslydhh
7da469da8b
park():prohibit spurious wakeups in next park
should consume this notification, so prohibit spurious wakeups in next park
2018-06-02 14:34:34 +08:00
Alex Crichton
c3a5d6b130 std: Minimize size of panicking on wasm
This commit applies a few code size optimizations for the wasm target to
the standard library, namely around panics. We notably know that in most
configurations it's impossible for us to print anything in
wasm32-unknown-unknown so we can skip larger portions of panicking that
are otherwise simply informative. This allows us to get quite a nice
size reduction.

Finally we can also tweak where the allocation happens for the
`Box<Any>` that we panic with. By only allocating once unwinding starts
we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-04-13 07:03:00 -07:00
Stjepan Glavina
27fae2b24a Remove thread_local_state 2018-02-28 18:59:12 +01:00
Stjepan Glavina
c99f4c4c5b Stabilize LocalKey::try_with 2018-02-28 12:41:36 +01:00
Corey Farwell
0a798bd952 Unify 'Platform-specific behavior' documentation headings. 2018-02-17 20:54:26 -05:00
Sebastian Dröge
b86bba5940 Make join a link to the function's documentation 2017-11-02 19:09:31 +02:00
Sebastian Dröge
a12f511910 Mention that panics can't possibly be caught when compiling with panic=abort 2017-11-02 18:33:25 +02:00
Sebastian Dröge
283b4a1b0b Use ` instead of ' for function names 2017-11-02 18:33:25 +02:00
Sebastian Dröge
5687000979 Update the std::thread docs and clarify that panics can nowadays be caught 2017-11-02 18:33:25 +02:00
Alex Crichton
6511e46753 std: Optimize thread park/unpark implementation
This is an adaptation of alexcrichton/futures-rs#597 for the standard library.
The goal here is to avoid locking a mutex on the "fast path" for thread
park/unpark where you're waking up a thread that isn't sleeping or otherwise
trying to park a thread that's already been notified. Mutex performance varies
quite a bit across platforms so this should provide a nice consistent speed
boost for the fast path of these functions.
2017-10-25 08:35:51 -07:00
Jake Goulding
b5b7666120 Don't encourage people to ignore threading errors in the docs 2017-10-08 10:29:32 -04:00
Alex Crichton
d5b0cbbeea Rollup merge of #44651 - bluss:document-thread-name-no-nuls, r=steveklabnik
Document thread builder panics for nul bytes in thread names

This seems to have been undocumented. Mention this where the name is set
(Builder::name) and where the panic could happen (Builder::spawn).

Thread::new is private and I think the builder is the only user where
this matters. A short comment was added to "document" Thread::new too.
2017-09-18 11:04:24 -05:00
Ulrik Sverdrup
7859c9ef44 std: Document thread builder panics for nul bytes in thread names
This seems to have been undocumented. Mention this where the name is set
(Builder::name) and where the panic could happen (Builder::spawn).

Thread::new is private and I think the builder is the only user where
this matters. A short comment was added to "document" Thread::new too.
2017-09-17 10:21:15 +02:00
Tobias Schaffner
b2b5063517 Move default stack min size to thread implementations
The default min stack size value is smaller on l4re and therefore
this value has to be different depending on the platform.
2017-09-13 10:56:41 +02:00
bors
93cdf5e3c4 Auto merge of #44112 - alexcrichton:thread-join, r=sfackler
std: Handle OS errors when joining threads

Also add to the documentation that the `join` method can panic.

cc #34971
cc #43539
2017-08-27 04:20:28 +00:00
Alex Crichton
dc7c7ba0c9 std: Handle OS errors when joining threads
Also add to the documentation that the `join` method can panic.

cc #34971
cc #43539
2017-08-26 19:36:46 -07:00
lukaramu
49ee9f3f08 Fix inconsistent doc headings
This fixes headings reading "Unsafety" and "Example", they should be
"Safety" and "Examples" according to RFC 1574.
2017-08-24 18:42:53 +02:00
Corey Farwell
1d5ee636d7 Thread spawning: don't run min_stack if the user has specified stack size. 2017-08-22 23:05:14 -04:00
Fourchaux
c7104be1a3 Fix typos & us spellings 2017-08-15 21:56:30 +02:00
Corey Farwell
659460191d Indicate which stack size option has precedence. 2017-08-14 15:03:31 -04:00
Corey Farwell
10bd80d79b Indicate thread names get passed to the OS. 2017-08-13 16:23:13 -04:00
Corey Farwell
150713ce9f Rewrite docs for stack size/thread names for spawned threads.
* Moves docs about stack size and thread naming from `Builder` to the
  `std::thread` module
* Adds more links to the new module-level documentation
* Mentions the 2 MiB stack size default, but indicate it's subject to
  change

Fixes https://github.com/rust-lang/rust/issues/43805.
2017-08-13 13:20:00 -04:00
Bastien Orivel
47cb3c5bc2 Fix some typos 2017-08-11 00:16:18 +02:00
Corey Farwell
4c08c131fa Indicate how ThreadId is created. 2017-08-02 23:16:34 -04:00
Corey Farwell
795db4c946 Fix broken links in Thread docs. 2017-08-02 23:16:33 -04:00
Mark Simulacrum
25e5f0a48d Rollup merge of #43456 - joshlf:spawn-doc-grammar, r=alexcrichton
std:🧵:spawn: Fix grammar in documentation

Closes #43435.
2017-07-26 06:15:04 -06:00
Joshua Liebow-Feeser
8aa8f80ac0 std:🧵:spawn: Fix grammar in documentation 2017-07-24 11:17:29 -07:00
Bruce Mitchener
539df8121b Fix some doc/comment typos. 2017-07-23 22:48:01 +07:00
Lee Bousfield
8b5549defb
Fix @alexcrichton comments 2017-07-11 11:04:19 -04:00
Steven Fackler
dc411e307a Stabilize ThreadId
Closes #21507
2017-06-24 19:19:26 -07:00
Alex Crichton
06540cb205 rustc: Enable #[thread_local] for Windows
I think LLVM has had support for quite some time now for this, we just never got
around to testing it out and binding it. We've had some trouble landing this in
the past I believe, but it's time to try again!

This commit flags the `#[thread_local]` attribute as being available for Windows
targets and adds an implementation of `register_dtor` in the `thread::local`
module to ensure we can destroy these keys. The same functionality is
implemented in clang via a function called `__tlregdtor` (presumably provided in
some Windows runtime somewhere), but this function unfortunately does not take a
data pointer (just a thunk) which means we can't easily call it. For now
destructors are just run in the same way the Linux fallback is implemented,
which is just keeping track via a single OS-based TLS key.
2017-06-23 16:11:39 -07:00
Mark Buer
0389d40ce0 Capture elapsed duration in Thread::park_timeout example 2017-06-12 13:43:58 +09:30
Mark Simulacrum
32f418f60a Rollup merge of #41981 - gamazeps:thread-detach, r=frewsxcv
[Doc] Expands `detach` documentation in `thread::JoinHande`.

Part of #29378 .

- Adds an example of a thread detaching.
- Expands what `detaching` means.

r? @steveklabnik
2017-06-02 09:10:41 -06:00
Felix Raimundo
b76b9e1467 Expands detach documentation in thread::JoinHande.
Part of #29378 .

- Adds an example of a thread detaching.
- Expands what `detaching` means.
2017-06-02 12:26:04 +02:00
Mark Simulacrum
8bac98a252 Rollup merge of #42141 - ids1024:nobacktrace, r=aturon
Fix building std without backtrace feature, which was broken in ca8b754

Fixes #42139
2017-05-24 19:50:02 -06:00
Mark Simulacrum
f4780a3f7c Rollup merge of #41980 - gamazeps:thread-send, r=steveklabnik
[Doc] Add `'static` and `Send` constraints explanations to `thread::spawn`

Part of #29378.

Explains why the constraints on the closure and its return value are `'static` and `Send`.

Allows to tick of `thread::spawn` from the list of things to document in the `thread` module.

r? @steveklabnik
2017-05-24 19:49:59 -06:00
Ian Douglas Scott
66237afce4
Fix building without backtrace feature, which was broken in ca8b754
Fixes #42139
2017-05-21 12:38:07 -07:00
Mark Simulacrum
18171a8861 Rollup merge of #41994 - gamazeps:thread-builder, r=GuillaumeGomez
[Doc] Implrove `thread::Builder`'s doc.

Part of #29378 .

- Explains *why* we would use the builder instead ofthe free function.
- Changes the parent-child explanation for a spawned-caller in `thread::Builder::spawn`
- Adds a link to `io::Result` in `thread::Builder`
- Corrects the return type doc in `thread::Builder::spawn`

r? @rust-lang/docs
2017-05-16 08:18:30 -06:00
Felix Raimundo
a51777ec87 Improve thread::Builder documentation.
Part of #29378 .

- In particular explains *why* we would use the builder instead of
  the free function.
- Changes the parent-child explanation for a spawned-caller.
- Add link to `io::Result` in `thread::Builder`
- Corrects the `thread::Builder::spawn` documentation.
2017-05-14 20:13:32 +02:00
Felix Raimundo
770bd57ea5 Add 'static and Send constraints explanations to thread::spawn
Part of #29378.
2017-05-14 14:14:42 +02:00
Felix Raimundo
a9cb094879 Explain why thread::yield_now could be used.
Part of #29378.
2017-05-14 14:05:10 +02:00
Mark Simulacrum
605d727bb3 Rollup merge of #41896 - tshepang:too-long, r=steveklabnik
doc: break into 2 sentences
2017-05-12 18:57:29 -06:00
Tshepang Lekhonkhobe
e42875ce6d doc: break into 2 sentences 2017-05-11 06:27:01 +02:00
Steve Klabnik
42ce11eb5a Rollup merge of #41854 - gamazeps:thread-spawn-doc, r=steveklabnik
[Doc] Improve `thread::spawn` documentation

Part of #29378

- Add two examples to `thread::spawn` doumentation that show common uses of threads.
- Add a link to `thread::Builder` in the `thread::spawn` documentation for configuring threads.
- Add a link to `thread::spawn` in `thread::Builder` in order to avoid documentation duplication.

r? @steveklabnik
2017-05-10 17:18:33 +02:00
Steve Klabnik
ec85859d9a Rollup merge of #41809 - gamazeps:thread-docs, r=steveklabnik
[DOC] Improve the thread::park and thread::unpark documentation

Part of #29378 .

Takes care of the documentation for `park`, `park_duration` and also improves the `unpark` example.

- `park should` have its module documentation inlined here, and cleaned up.
- `park_timeout` could use links to `park`.
2017-05-10 17:18:32 +02:00