<i id='ZRsJo'><tr id='ZRsJo'><dt id='ZRsJo'><q id='ZRsJo'><span id='ZRsJo'><b id='ZRsJo'><form id='ZRsJo'><ins id='ZRsJo'></ins><ul id='ZRsJo'></ul><sub id='ZRsJo'></sub></form><legend id='ZRsJo'></legend><bdo id='ZRsJo'><pre id='ZRsJo'><center id='ZRsJo'></center></pre></bdo></b><th id='ZRsJo'></th></span></q></dt></tr></i><div id='ZRsJo'><tfoot id='ZRsJo'></tfoot><dl id='ZRsJo'><fieldset id='ZRsJo'></fieldset></dl></div>
    1. <tfoot id='ZRsJo'></tfoot>
    2. <small id='ZRsJo'></small><noframes id='ZRsJo'>

    3. <legend id='ZRsJo'><style id='ZRsJo'><dir id='ZRsJo'><q id='ZRsJo'></q></dir></style></legend>

        <bdo id='ZRsJo'></bdo><ul id='ZRsJo'></ul>

      命名空间 std 中的 C++ 互斥锁未命名类型

      C++ mutex in namespace std does not name a type(命名空间 std 中的 C++ 互斥锁未命名类型)
        <i id='pqOzE'><tr id='pqOzE'><dt id='pqOzE'><q id='pqOzE'><span id='pqOzE'><b id='pqOzE'><form id='pqOzE'><ins id='pqOzE'></ins><ul id='pqOzE'></ul><sub id='pqOzE'></sub></form><legend id='pqOzE'></legend><bdo id='pqOzE'><pre id='pqOzE'><center id='pqOzE'></center></pre></bdo></b><th id='pqOzE'></th></span></q></dt></tr></i><div id='pqOzE'><tfoot id='pqOzE'></tfoot><dl id='pqOzE'><fieldset id='pqOzE'></fieldset></dl></div>
        <legend id='pqOzE'><style id='pqOzE'><dir id='pqOzE'><q id='pqOzE'></q></dir></style></legend>
          <tbody id='pqOzE'></tbody>
        • <bdo id='pqOzE'></bdo><ul id='pqOzE'></ul>

          <small id='pqOzE'></small><noframes id='pqOzE'>

            <tfoot id='pqOzE'></tfoot>

              • 本文介绍了命名空间 std 中的 C++ 互斥锁未命名类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在编写一个简单的 C++ 程序来演示锁的使用.我正在使用 codeblocksgnu gcc 编译器.

                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;
                }
                

                我收到以下错误:命名空间 std 中的互斥锁没有命名类型.

                为什么我会收到这个错误?编译器不支持使用锁吗?

                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 保护下定义的:

                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/ 和 https://sourceforge.net/projects/mingw-w64/files/.另外,正如 0xC0000022L 指出的,您需要下载 POSIX 线程版本(我上次没提到).

                The MinGW-w64 projects provides the necessary runtime support. Check out http://mingw-w64.sourceforge.net/ and https://sourceforge.net/projects/mingw-w64/files/. Also, as 0xC0000022L pointed out, you need to download the POSIX thread version (I missed mentioning it last time).

                这篇关于命名空间 std 中的 C++ 互斥锁未命名类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Is Type(::x); valid?(是类型(::x);有效的?)
                Difference between an inline function and static inline function(内联函数和静态内联函数的区别)
                Compilation fails randomly: quot;cannot open program databasequot;(编译随机失败:“无法打开程序数据库)
                Too many initializers error for a simple array in bcc32(bcc32 中的简单数组的初始值设定项过多错误)
                No Member named stoi in namespace std(命名空间 std 中没有名为 stoi 的成员)
                Error using a constexpr as a template parameter within the same class(在同一个类中使用 constexpr 作为模板参数时出错)
              • <tfoot id='uqRWT'></tfoot>

                  <small id='uqRWT'></small><noframes id='uqRWT'>

                    <i id='uqRWT'><tr id='uqRWT'><dt id='uqRWT'><q id='uqRWT'><span id='uqRWT'><b id='uqRWT'><form id='uqRWT'><ins id='uqRWT'></ins><ul id='uqRWT'></ul><sub id='uqRWT'></sub></form><legend id='uqRWT'></legend><bdo id='uqRWT'><pre id='uqRWT'><center id='uqRWT'></center></pre></bdo></b><th id='uqRWT'></th></span></q></dt></tr></i><div id='uqRWT'><tfoot id='uqRWT'></tfoot><dl id='uqRWT'><fieldset id='uqRWT'></fieldset></dl></div>
                      • <bdo id='uqRWT'></bdo><ul id='uqRWT'></ul>
                        <legend id='uqRWT'><style id='uqRWT'><dir id='uqRWT'><q id='uqRWT'></q></dir></style></legend>
                          <tbody id='uqRWT'></tbody>