Opened 8 years ago
Last modified 8 years ago
#10128 closed Feature Requests
Use lockable_adapter with const objects or const members — at Version 1
Reported by: | anonymous | Owned by: | viboes |
---|---|---|---|
Milestone: | Component: | thread | |
Version: | Boost 1.54.0 | Severity: | Problem |
Keywords: | Cc: |
Description (last modified by )
I would like to use lockable_adapter pattern with const objects. Usually, we need to access in protected mode to one const object (read some value).
We have a compiler error when we connect unique_lock and one derived class from lockable_adapter and the object is const.
int func(const Class1& obj) { boost::unique_lock<Class1> lock(obj); //boost::unique_lock<Class1> lock(const_cast<Class1&>(obj)); return obj.get(); }
->
error C2664: 'boost::unique_lock<Mutex>::unique_lock(boost::upgrade_lock<Mutex> &)' : no se puede convertir el parámetro 1 de 'const Class1' a 'boost::upgrade_lock<Mutex> &'
The solution for us is rewrite the sentence with one const_cast<Class1> -> boost::unique_lock<Class1> lock(const_cast<Class1&>(obj));
We are using Visual C++ 2010
Best regards
Change History (2)
by , 8 years ago
Attachment: | example_lock_constObject.cpp added |
---|
comment:1 by , 8 years ago
Description: | modified (diff) |
---|---|
Owner: | changed from | to
Status: | new → assigned |
Note:
See TracTickets
for help on using tickets.
Error example