std::unique_lock::swap(3)
π std::unique_lock::swap(3)
okay bestie, this is the C++ Standard Libary page for std::unique_lock::swap, and itβs lowkey iconic because itβs all about swapping lock state with zero drama. π
πΈ NAME πΈ
std::unique_lock::swap - std::unique_lock::swap
Thatβs literally the name bestie β no extra lore. π«Ά
β¨ Synopsis β¨
void swap( unique_lock& other ) noexcept; (since C++11)
It exchanges the internal states of the lock objects. Like, the locks trade places internally β vibe check passed. πβ¨
π Parameters π
otherβ the lock to swap the state with.
π Return value π
(none) β yep, it returns nothing, babe. Not a single value. π
π¦ Example π¦
// Run this code
#include <iostream>
#include <mutex>
int main()
{
std::mutex mtx1;
std::unique_lock<std::mutex> guard1(mtx1);
std::unique_lock<std::mutex> guard2;
guard2.swap(guard1);
if (!guard1 && guard2)
std::cout << "swapped success\n";
return 0;
}
π Output π
swapped success
π See also π
std::swap(std::unique_lock)β specialization ofstd::swapforunique_lock;(C++11)(function template).
okay bye bestie β this page is from cppreference.com (http://cppreference.com), version/date 2024.06.10, manual page std::unique_lock::swap(3). go swap something safely ππ«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms