[thread] Could mutex and condition_variable be movable?

Hi, I'm defining a class that is non copiable but movable. The class contains a boost::mutex and boost::condition_variable fields which are non copiable neither movable. I'd prefere not been forced to allocate all the class data in a pointer to make possible the move operation. Has a sens to make these classes movable? Thanks in advance --------------------------- Vicente Juan Botet Escriba

"vicente.botet" <vicente.botet@wanadoo.fr> writes:
I'm defining a class that is non copiable but movable. The class contains a boost::mutex and boost::condition_variable fields which are non copiable neither movable. I'd prefere not been forced to allocate all the class data in a pointer to make possible the move operation.
These classes cannot be made movable without forcing an additional level of indirection, since e.g. pthread_mutex_t is not movable. I would imagine that it is unsafe to move an object if other threads might be accessing it concurrently, since you will be moving the data that they are referencing. If there are no other threads, then you can just construct a new condition_variable or mutex in the destination. Anthony -- Anthony Williams | Just Software Solutions Ltd Custom Software Development | http://www.justsoftwaresolutions.co.uk Registered in England, Company Number 5478976. Registered Office: 15 Carrallack Mews, St Just, Cornwall, TR19 7UL

----- Original Message ----- From: "Anthony Williams" <anthony_w.geo@yahoo.com> To: <boost@lists.boost.org> Sent: Saturday, May 03, 2008 10:50 PM Subject: Re: [boost] [thread] Could mutex and condition_variable be movable?
"vicente.botet" <vicente.botet@wanadoo.fr> writes:
I'm defining a class that is non copiable but movable. The class contains a boost::mutex and boost::condition_variable fields which are non copiable neither movable. I'd prefere not been forced to allocate all the class data in a pointer to make possible the move operation.
These classes cannot be made movable without forcing an additional level of indirection, since e.g. pthread_mutex_t is not movable.
Thanks, this is what I suspected. I would add the additional level of indirection on my own class.
I would imagine that it is unsafe to move an object if other threads might be accessing it concurrently, since you will be moving the data that they are referencing. If there are no other threads, then you can just construct a new condition_variable or mutex in the destination.
Yes, you are right. I know what you have done to make booost::thread movable. Thanks again. Vicente
participants (2)
-
Anthony Williams
-
vicente.botet