]> git.lizzy.rs Git - rust.git/blob - src/docs/mutex_integer.txt
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
[rust.git] / src / docs / mutex_integer.txt
1 ### What it does
2 Checks for usages of `Mutex<X>` where `X` is an integral
3 type.
4
5 ### Why is this bad?
6 Using a mutex just to make access to a plain integer
7 sequential is
8 shooting flies with cannons. `std::sync::atomic::AtomicUsize` is leaner and faster.
9
10 ### Known problems
11 This lint cannot detect if the mutex is actually used
12 for waiting before a critical section.
13
14 ### Example
15 ```
16 let x = Mutex::new(0usize);
17 ```
18
19 Use instead:
20 ```
21 let x = AtomicUsize::new(0usize);
22 ```