Is std::lock() ill-defined, unimplementable, or useless?

后端 未结 4 666
没有蜡笔的小新
没有蜡笔的小新 2020-12-23 10:22

(Note: Much of this is redundant with commentary on Massive CPU load using std::lock (c++11), but I think this topic deserves its own question and answers.)

I recent

4条回答
  •  囚心锁ツ
    2020-12-23 10:36

    Did C++11 adopt this function from Boost?

    If so, Boost's description is instructive (emphasis mine):

    Effects: Locks the Lockable objects supplied as arguments in an unspecified and indeterminate order in a way that avoids deadlock. It is safe to call this function concurrently from multiple threads with the same mutexes (or other lockable objects) in different orders without risk of deadlock. If any of the lock() or try_lock() operations on the supplied Lockable objects throws an exception any locks acquired by the function will be released before the function exits.

提交回复
热议问题