You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/en-us/07-thread.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@ int main() {
31
31
We have already learned the basics of concurrency technology in the operating system, or the database, and `mutex` is one of the cores.
32
32
C++11 introduces a class related to `mutex`, with all related functions in the `<mutex>` header file.
33
33
34
-
`std::mutex` is the most basic `mutex` class in C++11, and you can create a mutex by instantiating `std::mutex`.
34
+
`std::mutex` is the most basic mutex class in C++11, and a mutex can be created by constructing a `std::mutex` object.
35
35
It can be locked by its member function `lock()`, and `unlock()` can be unlocked.
36
36
But in the process of actually writing the code, it is best not to directly call the member function,
37
37
Because calling member functions, you need to call `unlock()` at the exit of each critical section, and of course, exceptions.
@@ -160,7 +160,7 @@ After encapsulating the target to be called, you can use `get_future()` to get a
160
160
The condition variable `std::condition_variable` was born to solve the deadlock and was introduced when the mutex operation was not enough.
161
161
For example, a thread may need to wait for a condition to be true to continue execution.
162
162
A dead wait loop can cause all other threads to fail to enter the critical section so that when the condition is true, a deadlock occurs.
163
-
Therefore, the `condition_variable`instance is created primarily to wake up the waiting thread and avoid deadlocks.
163
+
Therefore, the `condition_variable`object is created primarily to wake up the waiting thread and avoid deadlocks.
164
164
`notify_one()` of `std::condition_variable` is used to wake up a thread;
165
165
`notify_all()` is to notify all threads. Below is an example of a producer and consumer model:
166
166
@@ -276,8 +276,8 @@ This is a very strong set of synchronization conditions, in other words when it
276
276
This seems too harsh for a variable that requires only atomic operations (no intermediate state).
277
277
278
278
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.
279
-
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 an
280
-
Atomic type read and write operations are minimized from a set of instructions to a single CPU instruction. E.g:
279
+
Therefore, the `std::atomic` template is introduced in C++11 for the topic of multi-threaded shared variable reading and writing, which enables us to instantiate atomic types,
280
+
and minimize an atomic read or write operation from a set of instructions to a single CPU instruction. E.g:
0 commit comments