我正在编写一个简单的C++程序来演示锁的使用.我正在使用codeblocks和gnu gcc编译器.
#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;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:mutex in namespace std does not name a type.
为什么我收到此错误?编译器是否支持使用锁?