命名空间std中的C ++ mutex不命名类型 [英] C++ mutex in namespace std does not name a type

查看:5483
本文介绍了命名空间std中的C ++ mutex不命名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个简单的c ++程序来演示锁的使用。使用代码块 gnu gcc

Am doing a simple c++ program to demonstrate the use of locks. 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;
}

得到以下错误:不命名类型。为什么会收到此错误?编译器是否支持使用锁?

Am 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?

推荐答案

我碰巧遇到了同样的问题。 GCC在Linux下使用 std :: mutex 正常工作。然而,在Windows上的东西似乎更糟。在< mutex>头文件随MinGW GCC 4.7.2(我相信你也使用MinGW GCC版本),我发现互斥体类定义在以下 #if guard :

I happened to be looking at the same problem. GCC works fine with std::mutex under Linux. However, on Windows things seem to be worse. In the <mutex> header file shipped with MinGW GCC 4.7.2 (I believe you are using a MinGW GCC version too), I have found that the mutex class is defined under the following #if guard:

#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1)

遗憾的是, _GLIBCXX_HAS_GTHREADS 未在Windows上定义。

Regretfully, _GLIBCXX_HAS_GTHREADS is not defined on Windows. The runtime support is simply not there.

您可能还想直接在MinGW邮件列表上提出问题,以防某些GCC专家可能帮助您。

You may also want to ask questions directly on the MinGW mailing list, in case some GCC gurus may help you out.

编辑:MinGW-w64项目提供必要的运行时支持。请查看 http://mingw-w64.sourceforge.net/

The MinGW-w64 projects provides the necessary runtime support. Check out http://mingw-w64.sourceforge.net/

这篇关于命名空间std中的C ++ mutex不命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆