public member function
<mutex>
std::unique_lock::operator= move (1)unique_lock& operator= (unique_lock&& x) noexcept;copy [deleted] (2)
unique_lock& operator= (const unique_lock&) = delete;move (1)
unique_lock& operator= (unique_lock&& x);copy [deleted] (2)
unique_lock& operator= (const unique_lock&) = delete;
Move-assign unique_lock
Replaces the managed mutex object by the one in x, including its owning state.If the object owned a lock on its managed mutex object before the call, its unlock member is called before being replaced.
x is left in the same state as if default-constructed (referring to no mutex object).
unique_lock objects cannot be copied (2).
*this
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// unique_lock::operator= example
#include <iostream> // std::cout
#include <thread> // std::thread
#include <mutex> // std::mutex, std::unique_lock
std::mutex mtx; // mutex for critical section
void print_fifty (char c) {
std::unique_lock<std::mutex> lck; // default-constructed
lck = std::unique_lock<std::mutex>(mtx); // move-assigned
for (int i=0; i<50; ++i) { std::cout << c; }
std::cout << '\n';
}
int main ()
{
std::thread th1 (print_fifty,'*');
std::thread th2 (print_fifty,'$');
th1.join();
th2.join();
return 0;
}
************************************************** $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
No-throw guarantee: never throws exceptions.
If the object
owns a lockon a managed
mutex objectbefore the call, that -for some reason- is not currently locked by the calling thread, it causes
undefined behavioron the attempt to
unlock it.
Otherwise, it throws no exceptions (no-throw guarantee).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4