Skip to content

Commit 7e6ada9

Browse files
authored
book: typo fixes (changkun#219)
1 parent b386fff commit 7e6ada9

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

book/en-us/07-thread.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main() {
6969
Because C++ guarantees that all stack objects will be destroyed at the end of the declaration period, such code is also extremely safe.
7070
Whether `critical_section()` returns normally or if an exception is thrown in the middle, a stack rollback is thrown, and `unlock()` is automatically called.
7171
72-
And `std::unique_lock` is more flexible than `std::lock_guard`, `std::unique_lock` is more flexible.
72+
`std::unique_lock` is more flexible than `std::lock_guard`.
7373
Objects of `std::unique_lock` manage the locking and unlocking operations on the `mutex` object with exclusive ownership (no other `unique_lock` objects owning the ownership of a `mutex` object). So in concurrent programming, it is recommended to use `std::unique_lock`.
7474
7575
`std::lock_guard` cannot explicitly call `lock` and `unlock`, and `std::unique_lock` can be called anywhere after the declaration.
@@ -255,7 +255,7 @@ int main() {
255255
}
256256
```
257257

258-
Intuitively, `a = 5;` seems in `t2` seems to always execute before `flag = 1;`, and `while (flag != 1)` in `t1` seems to guarantee `std ::cout << "b = " << b << std::endl;` will not be executed before the mark is changed. Logically, it seems that the value of `b` should be equal to 5.
258+
Intuitively, it seems that `a = 5;` in `t2` always executes before `flag = 1;` and `while (flag != 1)` in `t1`. It looks like there is a guarantee the line `std ::cout << "b = " << b << std::endl;` will not be executed before the mark is changed. Logically, it seems that the value of `b` should be equal to 5.
259259
But the actual situation is much more complicated than this, or the code itself is undefined behavior because, for `a` and `flag`, they are read and written in two parallel threads.
260260
There has been competition. Also, even if we ignore competing for reading and writing, it is still possible to receive out-of-order execution of the CPU and the impact of the compiler on the rearrangement of instructions.
261261
Cause `a = 5` to occur after `flag = 1`. Thus `b` may output 0.
@@ -272,7 +272,7 @@ This is a very strong set of synchronization conditions, in other words when it
272272
This seems too harsh for a variable that requires only atomic operations (no intermediate state).
273273

274274
The research on synchronization conditions has a very long history, and we will not go into details here. Readers should understand that under the modern CPU architecture, atomic operations at the CPU instruction level are provided.
275-
Therefore, in the C + + 11 multi-threaded shared variable reading and writing, the introduction of the `std::atomic` template, so that we instantiate an atomic type, will be a
275+
Therefore, in the C++11 multi-threaded shared variable reading and writing, the introduction of the `std::atomic` template, so that we instantiate an atomic type, will be a
276276
Atomic type read and write operations are minimized from a set of instructions to a single CPU instruction. E.g:
277277

278278
```cpp
@@ -544,7 +544,7 @@ They provide a critical foundation for standardized high-performance computing f
544544

545545
## Further Readings
546546

547-
- [C++ 并发编程(中文版)](https://www.amazon.com/dp/1617294691/ref=cm_sw_em_r_mt_dp_U_siEmDbRMMF960)
547+
- [C++ Concurrency in Action](https://www.amazon.com/dp/1617294691/ref=cm_sw_em_r_mt_dp_U_siEmDbRMMF960)
548548
- [Thread document](http://en.cppreference.com/w/cpp/thread)
549549
- Herlihy, M. P., & Wing, J. M. (1990). Linearizability: a correctness condition for concurrent objects. ACM Transactions on Programming Languages and Systems, 12(3), 463–492. https://doi.org/10.1145/78969.78972
550550

book/en-us/08-filesystem.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ order: 8
1010

1111
The file system library provides functions related to
1212
the operation of the file system, path, regular files, directories, and so on.
13-
Similar to the regular expression library, he was one of the first libraries
13+
Similar to the regular expression library, it was one of the first libraries
1414
to be launched by boost and eventually merged into the C++ standard.
1515

1616
## 8.1 Document and Link

0 commit comments

Comments
 (0)