I'm writing a simple C++ program to demonstrate the use of locks. I am using codeblocks
and gnu
gcc
compiler.
#include <iostream>
#include <thread>
#include <mutex>
using namespace std;
int x = 0; // shared variable
void synchronized_procedure()
{
static std::mutex m;
m.lock();
x = x + 1;
if (x < 5)
{
cout<<"hello";
}
m.unlock();
}
int main()
{
synchronized_procedure();
x=x+2;
cout<<"x is"<<x;
}
I'm getting the following error: mutex in namespace std does not name a type
.
Why am I getting this error? Doesn't the compiler support use of locks?
I don't know if it works for everybody, but in other way you just have to update your ndk. I'm using ndk-r11c and it works perfectly.
Many classes of the standard thread library can be replaced with the boost ones. A very easy workaround is to change the entire standard
mutex
file with a couple of lines.And do not forget to link against boost thread library.
I got the same error with gcc4.7.7.
After adding "-std=c++0x", it is fixed.