There is a great answer how to write move constructors for classes that contain std::mutex. But I wonder what the process is in implementing move constructors for objects containing condition_variable.
Asked
Active
Viewed 682 times
4
-
4But the move constructor/assignment operator in those answers doesn't move the mutex. It simply uses the mutex to lock access to the object, just like any other member function of `A`. And thus, it's based on the assumption of what that mutex is *for*. "Moving" the object does not move the locks of people who've locked the object presently. As such, what behavior do you want with a `condition_variable`? – Nicol Bolas Jan 19 '17 at 01:07
-
There are no clear and obvious semantics for what essential identity types (types for whom their identity is essential to their state) like mutex and condition variable should have when part of a composite object, especially when mixed with non-identity-essential data. You cannot in general move or copy their identity (if they are value types). Types like `std::future` *own* an identity, but they are not the identity themselves; they can be moved by moving the identity. In short, it depends what you want it to mean to be copied or moved, as Nicol states. – Yakk - Adam Nevraumont Jan 19 '17 at 15:22
-
2@NicolBolas Yes, as example shows, there is some proper algorithm how to write a move constructor/assignment operator for a class that has a `mutex`. I'm looking for a similar algorithm for a `condition_variable`. And maybe it is very simple. But an explanation will be useful. – ilya1725 Jan 19 '17 at 21:18