相关疑难解决方法(0)

命名空间std中的C++ mutex没有命名类型

我正在编写一个简单的C++程序来演示锁的使用.我正在使用codeblocksgnu 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.

为什么我收到此错误?编译器是否支持使用锁?

c++ multithreading locking mingw compiler-errors

24
推荐指数
5
解决办法
5万
查看次数

标签 统计

c++ ×1

compiler-errors ×1

locking ×1

mingw ×1

multithreading ×1