diff --git a/book/en-us/07-thread.md b/book/en-us/07-thread.md index 14f7406..8173aef 100644 --- a/book/en-us/07-thread.md +++ b/book/en-us/07-thread.md @@ -67,7 +67,9 @@ int main() { ``` Because C++ guarantees that all stack objects will be destroyed at the end of the declaration period, such code is also extremely safe. -Whether `critical_section()` returns normally or if an exception is thrown in the middle, a stack rollback is thrown, and `unlock()` is automatically called. +Whether `critical_section()` returns normally or if an exception is thrown in the middle, a stack unwinding is thrown, and `unlock()` is automatically called. + +> An exception is thrown and not caught (it is implementation-defined whether any stack unwinding is done in this case). `std::unique_lock` is more flexible than `std::lock_guard`. 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`. diff --git a/book/zh-cn/07-thread.md b/book/zh-cn/07-thread.md index c32a3c6..ba80e7e 100644 --- a/book/zh-cn/07-thread.md +++ b/book/zh-cn/07-thread.md @@ -68,7 +68,9 @@ int main() { ``` 由于 C++ 保证了所有栈对象在生命周期结束时会被销毁,所以这样的代码也是异常安全的。 -无论 `critical_section()` 正常返回、还是在中途抛出异常,都会引发堆栈回退,也就自动调用了 `unlock()`。 +无论 `critical_section()` 正常返回、还是在中途抛出异常,都会引发栈回溯,也就自动调用了 `unlock()`。 + +> 没有捕获抛出的异常(此时由实现定义是否进行栈回溯)。 而 `std::unique_lock` 则是相对于 `std::lock_guard` 出现的,`std::unique_lock` 更加灵活, `std::unique_lock` 的对象会以独占所有权(没有其他的 `unique_lock` 对象同时拥有某个 `mutex` 对象的所有权)