Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::unique_lock<Mutex>::operator=

      From cppreference.com
      <cpp‎ |thread‎ |unique lock
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Condition variables
      (C++11)
      Semaphores
      Latches and Barriers
      (C++20)
      (C++20)
      Futures
      (C++11)
      (C++11)
      (C++11)
      Safe reclamation
      Hazard pointers
      Atomic types
      (C++11)
      (C++20)
      Initialization of atomic types
      (C++11)(deprecated in C++20)
      (C++11)(deprecated in C++20)
      Memory ordering
      (C++11)(deprecated in C++26)
      Free functions for atomic operations
      Free functions for atomic flags
       
       
      unique_lock& operator=( unique_lock&& other)noexcept;
      (since C++11)

      Move assignment operator. Equivalent tounique_lock{std::move(other)}.swap(*this);return*this;.

      Ifother is the same object as*this, there is no effect. Otherwise, if prior to the call*this has an associated mutex and has acquired ownership of it, the mutex is unlocked.

      Contents

      [edit]Parameters

      other - anotherunique_lock to replace the state with

      [edit]Return value

      *this

      [edit]Notes

      With a recursive mutex it is possible for both*this andother to own the same mutex before the assignment. In this case,*this will own the mutex after the assignment andother will not.

      The move assignment possibly raises undefined behavior. For example, when*this is constructed withstd::adopt_lock, but the calling thread does not have the ownership of the associated mutex, the ownership of the associated mutex cannot be properly released.

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2104C++11the move assignment operator wasnoexcept but could have undefined behaviornoexcept removed
      LWG 4172C++11LWG2104 removednoexcept
      self-move-assignment ofunique_lock was incorrectly specified
      noexcept restored
      respecified as no-op
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/unique_lock/operator%3D&oldid=181323"

      [8]ページ先頭

      ©2009-2026 Movatter.jp