I've been trying to use scoped_lock in VS2019 when trying to make a thread safe database class that uses an underlying queue, also thread-safe, to execute operations fed into it. It's a basic class compared to what I've seen out there, but I can't overcome this one error to see if it's reliable or not:
Code:
Severity Code Description Project File Line Suppression State
Error C2662 'void std::_Mutex_base::unlock(void)': cannot convert 'this' pointer from '_Mutex' to 'std::_Mutex_base &' cmmnet C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex 488
The output log is even more confusing:
Code:
1>tssqlite.cpp
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex(488,1): error C2662: 'void std::_Mutex_base::unlock(void)': cannot convert 'this' pointer from '_Mutex' to 'std::_Mutex_base &'
1> with
1> [
1> _Mutex=const std::mutex
1> ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex(488,9): message : Conversion loses qualifiers
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex(66,10): message : see declaration of 'std::_Mutex_base::unlock'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\mutex(487): message : while compiling class template member function 'std::scoped_lock<const std::mutex>::~scoped_lock(void) noexcept'
1>C:\Users\admin\Documents\GitHub\network-interface\src\tssqlite.cpp(45): message : see reference to function template instantiation 'std::scoped_lock<const std::mutex>::~scoped_lock(void) noexcept' being compiled
1>C:\Users\admin\Documents\GitHub\network-interface\src\tssqlite.cpp(45): message : see reference to class template instantiation 'std::scoped_lock<const std::mutex>' being compiled
1>tsmysql.cpp
The class contains a std::mutex which I only use like this. It works in the thread safe wrapper class for my queue, but not here?
Code:
int TSSQLite::GetLastResult() const
{
std::scoped_lock lock(m_mutex);
return m_current.result;
}
Whereas MSVC has no issue with this:
Code:
template <class T>
const T& TSQueue<T>::Front()
{
std::scoped_lock lock(m_mutex);
return m_queue.front();
}