Skip to content

Commit 7b57e5e

Browse files
authored
book: revise the description of RAII (#288)
1 parent 2659a5f commit 7b57e5e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

book/en-us/07-thread.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ C++11 introduces a class related to `mutex`, with all related functions in the `
3535
It can be locked by its member function `lock()`, and `unlock()` can be unlocked.
3636
But in the process of actually writing the code, it is best not to directly call the member function,
3737
Because calling member functions, you need to call `unlock()` at the exit of each critical section, and of course, exceptions.
38-
At this time, C++11 also provides a template class `std::lock_guard` for the RAII syntax for the mutex.
38+
At this time, C++11 also provides a template class `std::lock_guard` for the RAII mechanism for the mutex.
3939

4040
RAII guarantees the exceptional security of the code while keeping the simplicity of the code.
4141

book/zh-cn/07-thread.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ C++11 引入了 `mutex` 相关的类,其所有相关的函数都放在 `<mutex
3535
而通过其成员函数 `lock()` 可以进行上锁,`unlock()` 可以进行解锁。
3636
但是在实际编写代码的过程中,最好不去直接调用成员函数,
3737
因为调用成员函数就需要在每个临界区的出口处调用 `unlock()`,当然,还包括异常。
38-
这时候 C++11 还为互斥量提供了一个 RAII 语法的模板类 `std::lock_guard`
38+
而 C++11 为互斥量提供了一个 RAII 机制的模板类 `std::lock_guard`
39+
3940
RAII 在不失代码简洁性的同时,很好的保证了代码的异常安全性。
4041

4142
在 RAII 用法下,对于临界区的互斥量的创建只需要在作用域的开始部分,例如:

0 commit comments

Comments
 (0)