Re: [Boost-bugs] [Boost C++ Libraries] #10128: Use lockable_adapter with const objects or const members

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #10128: Use lockable_adapter with const objects or const members
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-07-08 18:27:08


#10128: Use lockable_adapter with const objects or const members
-------------------------------+----------------------
  Reporter: anonymous | Owner: viboes
      Type: Feature Requests | Status: assigned
 Milestone: To Be Determined | Component: thread
   Version: Boost 1.54.0 | Severity: Problem
Resolution: | Keywords:
-------------------------------+----------------------

Comment (by anonymous):

 Then, If I try to change class1 with this code


 {{{
 class Class1 :
     public boost::recursive_mutex
 {
 public:
     Class1() :_i(0){}
     virtual ~Class1(){}

     void set(int i) {
         _i = i;
     }

     int get() const {
         return _i;
     }

 private:
     int _i;
 };

 int func(const Class1& obj)
 {
     boost::unique_lock<const Class1> lock(obj);
     //boost::unique_lock<Class1> lock(obj);
     //boost::unique_lock<Class1> lock(const_cast<Class1&>(obj));
     return obj.get();
 }


 int _tmain(int argc, _TCHAR* argv[])
 {
     Class1 obj;
     {
     boost::unique_lock<Class1> lock(obj);
     obj.set(1);
     }

     func(obj);

         return 0;
 }

 }}}

 Visual C++ 2010 says me:

 {{{
 1>c:\desarrollo\externo\boost\boost_1_55_0\boost\thread\lock_types.hpp(331):
 error C2662:
 'boost::detail::basic_recursive_mutex_impl<underlying_mutex_type>::unlock'
 : no se puede convertir el puntero 'this' de 'const Class1' a
 'boost::detail::basic_recursive_mutex_impl<underlying_mutex_type> &'
 1> with
 1> [
 1> underlying_mutex_type=boost::detail::basic_timed_mutex
 1> ]
 1> Se pierden calificadores en la conversión
 1>
 c:\desarrollo\externo\boost\boost_1_55_0\boost\thread\lock_types.hpp(328)
 : durante la compilación de la función miembro de plantilla de clase
 'boost::unique_lock<Mutex>::~unique_lock(void)'
 1> with
 1> [
 1> Mutex=const Class1
 1> ]
 1>
 c:\temp\example_lock_constobject\example_lock_constobject.cpp(50) : vea la
 referencia a la creación de instancias de plantilla de clase
 'boost::unique_lock<Mutex>' que se está compilando
 1> with
 1> [
 1> Mutex=const Class1
 1> ]
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10128#comment:12>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:16 UTC