Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #93245

Merged
merged 36 commits into from
Jan 24, 2022
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0e24ad5
Implement RFC 3151: Scoped threads.
m-ou-se Jan 4, 2022
cc699e1
Add ScopedJoinHandle::is_running().
m-ou-se Jan 4, 2022
da33da1
Add documentation for scoped threads.
m-ou-se Jan 4, 2022
f521779
Simplify panicking mechanism of thread::scope.
m-ou-se Jan 4, 2022
4300bea
Formatting.
m-ou-se Jan 4, 2022
c5cb2de
Fix variance of thread::Scope.
m-ou-se Jan 4, 2022
2c8cc70
Use > rather than == for overflow check in scoped threads.
m-ou-se Jan 4, 2022
09e6665
Fix typo in documentation.
m-ou-se Jan 4, 2022
c429ade
Fix typo in is_running() docs.
m-ou-se Jan 4, 2022
5b5746f
Fix typo in Scope::spawn docs.
m-ou-se Jan 4, 2022
a9efbaf
Rename n_running_threads to num_running_threads.
m-ou-se Jan 5, 2022
5bd5781
Fix missing .load() in Scope's Debug impl.
m-ou-se Jan 5, 2022
aa9c088
Note the invariance over 'env in Scope<'env>.
m-ou-se Jan 5, 2022
4cb7370
Mention *scoped* thread in panic message.
m-ou-se Jan 5, 2022
bc8cef1
rustc_mir_itertools: Avoid needless `collect` with itertools
mati865 Jan 22, 2022
e572c5a
Simplify Send/Sync of std::thread::Packet.
m-ou-se Jan 22, 2022
12cc7d9
Add tracking issue number for scoped_threads.
m-ou-se Jan 22, 2022
465c405
Add test for thread::Scope invariance.
m-ou-se Jan 22, 2022
cbb0fff
Fix let_chains and if_let_guard feature flags
c410-f3r Jan 22, 2022
4ff7e6e
Normalize field access types during borrowck
compiler-errors Jan 23, 2022
19809ed
Add preliminary support for inline assembly for msp430.
cr1901 Jan 20, 2022
cf382de
Remove DiagnosticBuilder.quiet
mark-i-m Jan 23, 2022
452aa81
rustc_lint: Remove some redundant fields from `EarlyContext`
petrochenkov Sep 27, 2021
51b2338
rustc_lint: Reuse the set of registered tools from resolver
petrochenkov Sep 28, 2021
9c70b6d
Update clippy
petrochenkov Dec 4, 2021
05cd755
rustc_lint: Stop creating a fake `ast::Crate` for running early lints
petrochenkov Dec 7, 2021
67cccaf
expand: Pass everything by reference to pre-expansion lint callback
petrochenkov Dec 11, 2021
4a74ace
Liberate late bound regions when collecting GAT substs in wfcheck
compiler-errors Jan 23, 2022
89baf0f
Rollup merge of #91526 - petrochenkov:earlint, r=cjgillot
matthiaskrgr Jan 23, 2022
bb260e8
Rollup merge of #92555 - m-ou-se:scoped-threads, r=Amanieu
matthiaskrgr Jan 23, 2022
0f2ff4b
Rollup merge of #93213 - c410-f3r:let-chains-feature, r=matthewjasper
matthiaskrgr Jan 23, 2022
552b564
Rollup merge of #93219 - cr1901:msp430-asm-squashed, r=Amanieu
matthiaskrgr Jan 23, 2022
5adef28
Rollup merge of #93226 - compiler-errors:issue-93141, r=jackh726
matthiaskrgr Jan 23, 2022
8810af8
Rollup merge of #93227 - compiler-errors:gat-hrtb-wfcheck, r=jackh726
matthiaskrgr Jan 23, 2022
a1645e5
Rollup merge of #93229 - mark-i-m:noquiet, r=eddyb
matthiaskrgr Jan 23, 2022
eea833f
Rollup merge of #93234 - mati865:mir-transform-use-itertools, r=jackh726
matthiaskrgr Jan 23, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Rename n_running_threads to num_running_threads.
m-ou-se committed Jan 5, 2022
commit a9efbaf3a500a8670491bdc18012a7ebfbc1c122
4 changes: 2 additions & 2 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
@@ -505,7 +505,7 @@ impl Builder {
};

if let Some(scope_data) = scope_data {
scope_data.increment_n_running_threads();
scope_data.increment_num_running_threads();
}

Ok(JoinInner {
@@ -1292,7 +1292,7 @@ impl<'scope, T> Drop for Packet<'scope, T> {
// panicked, and nobody consumed the panic payload, we make sure
// the scope function will panic.
let unhandled_panic = matches!(self.result.get_mut(), Some(Err(_)));
scope.decrement_n_running_threads(unhandled_panic);
scope.decrement_num_running_threads(unhandled_panic);
}
}
}
18 changes: 9 additions & 9 deletions library/std/src/thread/scoped.rs
Original file line number Diff line number Diff line change
@@ -20,26 +20,26 @@ pub struct Scope<'env> {
pub struct ScopedJoinHandle<'scope, T>(JoinInner<'scope, T>);

pub(super) struct ScopeData {
n_running_threads: AtomicUsize,
num_running_threads: AtomicUsize,
a_thread_panicked: AtomicBool,
main_thread: Thread,
}

impl ScopeData {
pub(super) fn increment_n_running_threads(&self) {
pub(super) fn increment_num_running_threads(&self) {
// We check for 'overflow' with usize::MAX / 2, to make sure there's no
// chance it overflows to 0, which would result in unsoundness.
if self.n_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
if self.num_running_threads.fetch_add(1, Ordering::Relaxed) > usize::MAX / 2 {
// This can only reasonably happen by mem::forget()'ing many many ScopedJoinHandles.
self.decrement_n_running_threads(false);
self.decrement_num_running_threads(false);
panic!("too many running threads in thread scope");
}
}
pub(super) fn decrement_n_running_threads(&self, panic: bool) {
pub(super) fn decrement_num_running_threads(&self, panic: bool) {
if panic {
self.a_thread_panicked.store(true, Ordering::Relaxed);
}
if self.n_running_threads.fetch_sub(1, Ordering::Release) == 1 {
if self.num_running_threads.fetch_sub(1, Ordering::Release) == 1 {
self.main_thread.unpark();
}
}
@@ -98,7 +98,7 @@ where
{
let scope = Scope {
data: ScopeData {
n_running_threads: AtomicUsize::new(0),
num_running_threads: AtomicUsize::new(0),
main_thread: current(),
a_thread_panicked: AtomicBool::new(false),
},
@@ -109,7 +109,7 @@ where
let result = catch_unwind(AssertUnwindSafe(|| f(&scope)));

// Wait until all the threads are finished.
while scope.data.n_running_threads.load(Ordering::Acquire) != 0 {
while scope.data.num_running_threads.load(Ordering::Acquire) != 0 {
park();
}

@@ -287,7 +287,7 @@ impl<'scope, T> ScopedJoinHandle<'scope, T> {
impl<'env> fmt::Debug for Scope<'env> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Scope")
.field("n_running_threads", &self.data.n_running_threads.load(Ordering::Relaxed))
.field("num_running_threads", &self.data.num_running_threads.load(Ordering::Relaxed))
.field("a_thread_panicked", &self.data.a_thread_panicked)
.field("main_thread", &self.data.main_thread)
.finish_non_exhaustive()