Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7c75e39
panic_immediate_abort requires abort as a panic strategy
tmiasko Mar 8, 2023
dbe1649
Fix LVI generic load test
raoulstrackx Feb 21, 2023
782e69e
Fix LVI inline assembly test
raoulstrackx Feb 22, 2023
2743dc6
Ignore LVI incompatible assembly tests on sgx platform
raoulstrackx Mar 9, 2023
8428090
Fix run-make LVI tests
raoulstrackx Feb 22, 2023
d69ebf7
Ignore sgx platform for issue-36710
raoulstrackx Mar 9, 2023
05542d9
fix typo in the creation of OpenOption
stlankes Mar 19, 2023
db5dfd2
Add block-based mutex unlocking example
the8472 Mar 14, 2023
a3e41b5
Apply suggestions from code review
the8472 Mar 20, 2023
e600c0b
rustdoc: add support for type filters in arguments and generics
notriddle Mar 1, 2023
cae4385
doc: add generics improvements to rustdoc book
notriddle Mar 3, 2023
485aec4
Add AixLinker to support linking on AIX
Mar 23, 2023
f116110
Fix copy-paste error
Mar 23, 2023
3957d3a
Adjust debug info stripping
Mar 23, 2023
71927ad
resolve: Rename some cstore methods to match queries and add comments
petrochenkov Mar 23, 2023
1cec923
rustc_metadata: Freeze cstore after the full crate list is queried
petrochenkov Mar 23, 2023
e55f73a
Refine error spans for const args in hir typeck
compiler-errors Mar 9, 2023
2bab422
Return nested obligations from canonical response var unification
compiler-errors Mar 22, 2023
6c6bd01
Note type mismatch on ConstArgHasType
compiler-errors Mar 9, 2023
1680334
Use fulfillment in InferCtxt::evaluate_obligation
compiler-errors Mar 23, 2023
eb46afb
Rollup merge of #108629 - notriddle:notriddle/item-type-advanced, r=G…
matthiaskrgr Mar 24, 2023
d9c05b8
Rollup merge of #108924 - tmiasko:panic-immediate-abort, r=thomcc
matthiaskrgr Mar 24, 2023
eb82a5a
Rollup merge of #108961 - compiler-errors:refine-ct-errors, r=BoxyUwU
matthiaskrgr Mar 24, 2023
cfd8105
Rollup merge of #108986 - fortanix:raoul/sync_lvi_patches, r=cuviper
matthiaskrgr Mar 24, 2023
605a4fc
Rollup merge of #109142 - the8472:mutex-block-docs, r=cuviper
matthiaskrgr Mar 24, 2023
cca2630
Rollup merge of #109368 - hermitcore:typo, r=cuviper
matthiaskrgr Mar 24, 2023
1c7ef3b
Rollup merge of #109493 - compiler-errors:new-solver-vars-obligations…
matthiaskrgr Mar 24, 2023
686bd46
Rollup merge of #109515 - bzEq:aix-linker, r=petrochenkov
matthiaskrgr Mar 24, 2023
4d21d30
Rollup merge of #109536 - petrochenkov:qcstore3, r=cjgillot
matthiaskrgr Mar 24, 2023
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
Add block-based mutex unlocking example
  • Loading branch information
the8472 committed Mar 20, 2023
commit db5dfd2373fb6774bf7d95f3dbab0818415f421b
24 changes: 17 additions & 7 deletions library/std/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ use crate::sys::locks as sys;
/// *guard += 1;
/// ```
///
/// It is sometimes necessary to manually drop the mutex guard to unlock it
/// sooner than the end of the enclosing scope.
/// It is sometimes necessary to manually drop the mutex guard or to create an inner scope
/// to unlock it sooner than the end of the enclosing scope.
///
/// ```
/// use std::sync::{Arc, Mutex};
Expand All @@ -125,11 +125,18 @@ use crate::sys::locks as sys;
/// let res_mutex_clone = Arc::clone(&res_mutex);
///
/// threads.push(thread::spawn(move || {
/// let mut data = data_mutex_clone.lock().unwrap();
/// // This is the result of some important and long-ish work.
/// let result = data.iter().fold(0, |acc, x| acc + x * 2);
/// data.push(result);
/// drop(data);
/// // Here we use a block to limit the lifetime of the lock guard.
/// let result = {
/// let mut data = data_mutex_clone.lock().unwrap();
/// // This is the result of some important and long-ish work.
/// let result = data.iter().fold(0, |acc, x| acc + x * 2);
/// data.push(result);
/// result
/// // The mutex guard gets dropped here, together with any other values
/// // created in the critical section.
/// };
/// // The guard created here is a temporary dropped at the end of the statement, i.e.
/// // the lock would not remain being held even if the thread did some additional work.
/// *res_mutex_clone.lock().unwrap() += result;
/// }));
/// });
Expand All @@ -146,6 +153,8 @@ use crate::sys::locks as sys;
/// // It's even more important here than in the threads because we `.join` the
/// // threads after that. If we had not dropped the mutex guard, a thread could
/// // be waiting forever for it, causing a deadlock.
/// // As in the threads a block could have been used instead of calling the
/// // `drop` function.
/// drop(data);
/// // Here the mutex guard is not assigned to a variable and so, even if the
/// // scope does not end after this line, the mutex is still released: there is
Expand All @@ -160,6 +169,7 @@ use crate::sys::locks as sys;
///
/// assert_eq!(*res_mutex.lock().unwrap(), 800);
/// ```
///
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "Mutex")]
pub struct Mutex<T: ?Sized> {
Expand Down