I have implemented a ReadLock like following:
In my myClass.h
#include <boost/thread/locks.hpp>
#include <boost/thread/shared_mutex.hpp>
typedef boost::shared_mutex Lock;
typedef boost::shared_lock< Lock > ReadLock;
Lock myLock;
In myClass.cpp:
void ReadFunction() const
{
ReadLock r_lock(myLock); // Error!
//Do reader stuff
}
The code works in VS2010 but failed with GCC4.0. The compiler is throwing error at ReadLock saying there is no matching function. I suspect is the "const" correctness problem with the variable myLock. When I removed the const in the function declaration, the error disappeared. Can anybody explain this to me? Why this works under windows but not with gcc?
Any suggestion here? Thanks.