std::unique_lock<Mutex>::operator=
來自 cppreference.com
< cpp | thread | unique lock
unique_lock& operator=( unique_lock&& other ) noexcept; |
(C++11 起) | |
移動賦值運算子。等價於 unique_lock{std::move(other)}.swap(*this); return *this;。
如果 other 與 *this 是同一個物件,則沒有效果。否則,如果在呼叫之前 *this 擁有關聯的互斥體並已獲得其所有權,則互斥體將被解鎖。
目錄 |
[編輯] 引數
其他 | - | 另一個 unique_lock ,用於替換狀態 |
[編輯] 返回值
*this
[編輯] 注意
對於遞迴互斥體,在賦值之前 *this 和 other 都可能擁有相同的互斥體。在這種情況下,賦值後 *this 將擁有互斥體,而 other 將不擁有。
移動賦值可能會導致未定義行為。例如,當 *this 以 std::adopt_lock 構造時,但呼叫執行緒不擁有關聯的互斥體,則關聯互斥體的所有權無法正確釋放。
[編輯] 缺陷報告
下列更改行為的缺陷報告追溯地應用於以前出版的 C++ 標準。
缺陷報告 | 應用於 | 釋出時的行為 | 正確的行為 |
---|---|---|---|
LWG 2104 | C++11 | 移動賦值運算子是 noexcept 但可能存在未定義行為 | 移除 noexcept |
LWG 4172 | C++11 | LWG2104 移除了 noexceptunique_lock 的自移動賦值被錯誤指定 |
恢復 noexcept 重新指定為無操作 |