about summary refs log tree commit diff
path: root/library/std/src/thread
AgeCommit message (Collapse)AuthorLines
2022-11-22Forbid inlining `thread_local!`'s `__getit` function on WindowsThom Chiovoloni-9/+16
2022-11-21reflow the stack size storyTshepang Mbambo-2/+4
2022-11-20Improve documentation of Stack sizeFabian Hintringer-3/+2
2022-11-12avoid using channels in thread-local testsIbraheem Ahmed-22/+44
2022-10-23Only test pthread_getname_np on linux-gnuJosh Stone-1/+7
2022-10-21Move truncation next to other thread tests for tidyJosh Stone-0/+25
2022-10-15Auto merge of #100579 - joboet:sync_mutex_everywhere, r=thomccbors-15/+12
std: use `sync::Mutex` for internal statics Since `sync::Mutex` is now `const`-constructible, it can be used for internal statics, removing the need for `sys_common::StaticMutex`. This adds some extra allocations on platforms which need to box their mutexes (currently SGX and some UNIX), but these will become unnecessary with the lock improvements tracked in #93740. I changed the program argument implementation on Hermit, it does not need `Mutex` but can use atomics like some UNIX systems (ping `@mkroening` `@stlankes).`
2022-10-15Rollup merge of #102773 - joboet:apple_parker, r=thomccDylan DPC-0/+22
Use semaphores for thread parking on Apple platforms Currently we use a mutex-condvar pair for thread parking on Apple systems. Unfortunately, `pthread_cond_timedwait` uses the real-time clock for measuring time, which causes problems when the system time changes. The parking implementation in this PR uses a semaphore instead, which measures monotonic time by default, avoiding these issues. As a further benefit, this has the potential to improve performance a bit, since `unpark` does not need to wait for a lock to be released. Since the Mach semaphores are poorly documented (I could not find availability or stability guarantees for instance), this uses a [dispatch semaphore](https://developer.apple.com/documentation/dispatch/dispatch_semaphore?language=objc) instead. While it adds a layer of indirection (it uses Mach semaphores internally), the overhead is probably negligible. Tested on macOS 12.5. r? ``````@thomcc``````
2022-10-14Auto merge of #102783 - RalfJung:tls, r=thomccbors-12/+25
sync thread_local key conditions exactly with what the macro uses This makes the `cfg` in `mod.rs` syntactically the same as those in `local.rs`. I don't think this should actually change anything, but seems better to be consistent? I looked into this due to https://github.com/rust-lang/rust/issues/102549, but this PR would make it *less* likely that `__OsLocalKeyInner` is going to get provided, so this cannot help with that issue. r? `@thomcc`
2022-10-13smarter way to avoid 'unused' warning when building for testsRalf Jung-9/+2
2022-10-13sync thread_local key conditions exactly with what the macro usesRalf Jung-10/+30
2022-10-13std: use `sync::Mutex` for internal staticsjoboet-15/+12
2022-10-11Rollup merge of #102589 - RalfJung:scoped-threads-dangling, r=m-ou-seYuki Okushi-0/+33
scoped threads: pass closure through MaybeUninit to avoid invalid dangling references The `main` function defined here looks roughly like this, if it were written as a more explicit stand-alone function: ```rust // Not showing all the `'lifetime` tracking, the point is that // this closure might live shorter than `thread`. fn thread(control: ..., closure: impl FnOnce() + 'lifetime) { closure(); control.signal_done(); // A lot of time can pass here. } ``` Note that `thread` continues to run even after `signal_done`! Now consider what happens if the `closure` captures a reference of lifetime `'lifetime`: - The type of `closure` is a struct (the implicit unnameable closure type) with a `&'lifetime mut T` field. References passed to a function are marked with `dereferenceable`, which is LLVM speak for *this reference will remain live for the entire duration of this function*. - The closure runs, `signal_done` runs. Then -- potentially -- this thread gets scheduled away and the main thread runs, seeing the signal and returning to the user. Now `'lifetime` ends and the memory the reference points to might be deallocated. - Now we have UB! The reference that as passed to `thread` with the promise of remaining live for the entire duration of the function, actually got deallocated while the function still runs. Oops. Long-term I think we should be able to use `ManuallyDrop` to fix this without `unsafe`, or maybe a new `MaybeDangling` type. I am working on an RFC for that. But in the mean time it'd be nice to fix this so that Miri with `-Zmiri-retag-fields` (which is needed for "full enforcement" of all the LLVM flags we generate) stops erroring on scoped threads. Fixes https://github.com/rust-lang/rust/issues/101983 r? `@m-ou-se`
2022-10-11Rollup merge of #102412 - joboet:dont_panic, r=m-ou-seYuki Okushi-2/+20
Never panic in `thread::park` and `thread::park_timeout` fixes #102398 `@rustbot` label +T-libs +T-libs-api
2022-10-06std: add thread parking testsjoboet-0/+22
2022-10-05tidyIbraheem Ahmed-2/+2
Co-authored-by: yvt <i@yvt.jp>
2022-10-03scoped threads: pass closure through MaybeUninit to avoid invalid dangling ↵Ralf Jung-0/+33
references
2022-10-02Rollup merge of #102313 - anirudh24seven:update_sleep_ms_doc, r=Mark-SimulacrumMatthias Krüger-0/+2
Update docs so that deprecated method points to relevant method The docs for the deprecated 'park_timeout_ms' method suggests that the user 'use park_timeout' method instead (at https://doc.rust-lang.org/std/thread/index.html). Making a similar change so that the docs for the deprecated `sleep_ms` method suggest that the user `use sleep` method instead.
2022-09-28std: never panic in `thread::park` and `thread::park_timeout`joboet-2/+20
2022-09-27Address feedbackmejrs-1/+1
2022-09-27Wrapper suggestionsmejrs-0/+1
2022-09-26Update docs so that deprecated method points to relevant methodAnirudh-0/+2
2022-09-09doc: fix minor typoAkhilesh Singhania-1/+1
2022-08-22update and extend some comments, and cfg-out some unused codeRalf Jung-7/+10
2022-08-22std: use realstd fast key when building testsRalf Jung-0/+10
2022-08-18add some Miri-only testsRalf Jung-0/+19
2022-08-10std: optimize thread ID generationjoboet-18/+41
2022-07-23Auto merge of #97925 - the8472:cgroupv1, r=joshtriplettbors-1/+6
Add cgroupv1 support to available_parallelism Fixes #97549 My dev machine uses cgroup v2 so I was only able to test that code path. So the v1 code path is written only based on documentation. I could use some help testing that it works on a machine with cgroups v1: ``` $ x.py build --stage 1 # quota.rs fn main() { println!("{:?}", std::thread::available_parallelism()); } # assuming stage1 is linked in rustup $ rust +stage1 quota.rs # spawn a new cgroup scope for the current user $ sudo systemd-run -p CPUQuota="300%" --uid=$(id -u) -tdS # should print Ok(3) $ ./quota ``` If it doesn't work as expected an strace, the contents of `/proc/self/cgroups` and the structure of `/sys/fs/cgroups` would help.
2022-07-22[review] mention that runtime may scale with # of mountpointsthe8472-0/+5
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
2022-07-21document memory orderings of `thread::{park, unpark}`Ibraheem Ahmed-9/+19
2022-07-15Fix typo in mod.rsIkko Ashimine-1/+1
constuct -> construct
2022-06-27fix data race in thread::scopeRalf Jung-10/+17
2022-06-20Improve docs for `is_running` to explain use caseJosh Triplett-6/+8
2022-06-15Test NLL fix of bad lifetime inference for reference captured in closure.Frank Steffahn-0/+13
2022-06-11Stabilize scoped threads.Mara Bos-10/+12
2022-06-09add cgroupv1 support to available_parallelismThe 8472-1/+1
2022-05-29Use Box::new() instead of box syntax in std testsest31-2/+2
2022-05-09Auto merge of #95960 - jhpratt:remove-rustc_deprecated, r=compiler-errorsbors-2/+2
Remove `#[rustc_deprecated]` This removes `#[rustc_deprecated]` and introduces diagnostics to help users to the right direction (that being `#[deprecated]`). All uses of `#[rustc_deprecated]` have been converted. CI is expected to fail initially; this requires #95958, which includes converting `stdarch`. I plan on following up in a short while (maybe a bootstrap cycle?) removing the diagnostics, as they're only intended to be short-term.
2022-05-01Fix some links in the standard libraryVadim Petrochenkov-0/+3
2022-04-25std: directly use pthread in UNIX parker implementationjoboet-5/+27
Mutex and Condvar are being replaced by more efficient implementations, which need thread parking themselves (see #93740). Therefore use the pthread synchronization primitives directly. Also, avoid allocating because the Parker struct is being placed in an Arc anyways.
2022-04-17Revert "Auto merge of #94373 - erikdesjardins:getitinl, r=Mark-Simulacrum"Erik Desjardins-2/+2
This reverts commit 035a717ee8bf548868fb50b5c7ca562fc4a657a7, reversing changes made to 761e8884858759b21f3374ad610494e68c087a38.
2022-04-14Remove use of `#[rustc_deprecated]`Jacob Pratt-2/+2
2022-04-12Add missing unsafe marker.Mara Bos-1/+1
This is now necessary because of deny(unsafe_op_in_unsafe_fn).
2022-04-12Add #[deny(unsafe_op_in_unsafe_fn)] to thread_local!(const).Mara Bos-0/+1
This avoids 'unused unsafe' warnings when using this feature inside std.
2022-04-07Use gender neutral termsJames 'zofrex' Sanderson-1/+1
2022-04-02Refer to u8 by absolute path in expansion of thread_localDavid Tolnay-3/+3
2022-04-01Fix `thread_local!` macro to be compatible with `no_implicit_prelude`niluxv-8/+8
Fixes issue #95533
2022-03-31Rollup merge of #95130 - workingjubilee:stably-finished, r=m-ou-seDylan DPC-2/+1
Stabilize thread::is_finished Closes #90470. r? `@m-ou-se`
2022-03-30Don't stabilize ScopedJoinHandle::is_finished yet.Mara Bos-1/+0
2022-03-29Make the stdlib largely conform to strict provenance.Aria Beingessner-3/+3
Some things like the unwinders and system APIs are not fully conformant, this only covers a lot of low-hanging fruit.