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

Add block-based mutex unlocking example #109142

Merged
merged 2 commits into from
Mar 24, 2023
Merged

Conversation

the8472
Copy link
Member

@the8472 the8472 commented Mar 14, 2023

This modifies the existing example in the Mutex docs to show both drop() and block based early unlocking.

Alternative to #81872, which is getting closed.

@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2023

r? @cuviper

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 14, 2023
@rustbot
Copy link
Collaborator

rustbot commented Mar 14, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

library/std/src/sync/mutex.rs Outdated Show resolved Hide resolved
/// result
/// // the mutex guard gets dropped here, together with any other values
/// // created in the critical section.
/// };
/// *res_mutex_clone.lock().unwrap() += result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's worth commenting that this res guard is a temporary, dropped at the end of this statement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is already mentioned in the 2nd example below which uses drop() instead of a block, but I added it here too.

library/std/src/sync/mutex.rs Outdated Show resolved Hide resolved
the8472 and others added 2 commits March 20, 2023 12:15
@the8472
Copy link
Member Author

the8472 commented Mar 20, 2023

@rustbot ready

@cuviper
Copy link
Member

cuviper commented Mar 23, 2023

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 23, 2023

📌 Commit a3e41b5 has been approved by cuviper

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 23, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 24, 2023
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#108629 (rustdoc: add support for type filters in arguments and generics)
 - rust-lang#108924 (panic_immediate_abort requires abort as a panic strategy)
 - rust-lang#108961 (Refine error spans for const args in hir typeck)
 - rust-lang#108986 (sync LVI tests)
 - rust-lang#109142 (Add block-based mutex unlocking example)
 - rust-lang#109368 (fix typo in the creation of OpenOption for RustyHermit)
 - rust-lang#109493 (Return nested obligations from canonical response var unification)
 - rust-lang#109515 (Add AixLinker to support linking on AIX)
 - rust-lang#109536 (resolve: Rename some cstore methods to match queries and add comments)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 605a4fc into rust-lang:master Mar 24, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants