简体   繁体   English

C++ Builder 10.4 社区版 => scoped_lock 丢失(至少似乎是一个路径混乱)

[英]C++ Builder 10.4 community edition => scoped_lock are missing (at least seems to be a path mess)

Just installed C++Builder 10.4 Community Edition.刚刚安装了 C++Builder 10.4 社区版。 My app is a console multi-threaded app, and uses std::scoped_lock (C++17).我的应用程序是一个控制台多线程应用程序,并使用std::scoped_lock (C++17)。

It seems that C++Builder chooses a <mutex> header file that does not define scoped_lock in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64 , where the <mutex> header file that is in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64\Dinkum\threads actually does define them, but is not the one used during include resolution. It seems that C++Builder chooses a <mutex> header file that does not define scoped_lock in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64 , where the <mutex> header file that is in C:\Program Files (x86)\Embarcadero\Studio\21.0\include\dinkumware64\Dinkum\threads实际上确实定义了它们,但不是在包含解析期间使用的。

What am I missing?我错过了什么? Has this ever been tested?这有没有被测试过?

Launch C++Builder fresh from install, create a new console, multi-threaded application, take the pre-generated shim code for main() and add this code:从安装中重新启动 C++Builder,创建一个新的控制台、多线程应用程序,为main()获取预先生成的 shim 代码并添加以下代码:

#pragma hdrstop
#pragma argsused

#include <mutex>

#ifdef _WIN32
#include <tchar.h>
#else
  typedef char _TCHAR;
  #define _tmain main
#endif

#include <stdio.h>

std::mutex m;

int _tmain(int argc, _TCHAR* argv[]) 
{
    std::scoped_lock lock(m);
    return 0;
}

And that will fail with an error:这将失败并出现错误:

no member named "std::scoped_lock" in namespace "std"命名空间“std”中没有名为“std::scoped_lock”的成员

The application is 32 bits, debug.该应用程序是 32 位,调试。 I've tried 64 bits as the <mutex> header is strangely located under dinkumware64/mutex , and debug no/debug, I've tried changing various options but no avail.我尝试了 64 位,因为<mutex> header 奇怪地位于dinkumware64/mutex下,并且调试无/调试,我尝试更改各种选项但无济于事。

Now under dinkumware64/Dinkum/threads/ , there is another "mutex" package that includes scoped_lock , but I have no idea why C++Builder selects it or not, and it's not in the std namespace anyway.现在在dinkumware64/Dinkum/threads/下,还有另一个“互斥锁” package 包含scoped_lock ,但我不知道为什么 C++Builder 会选择它,而且它也不在std命名空间中。

The standard library is located in dinkumware64 for 32-bit programs as well, so you should be looking there.标准库也位于dinkumware64中,用于 32 位程序,所以你应该去那里看看。

Problem is that scoped_lock is missing from the standard library.问题是标准库中缺少scoped_lock

You can easily implement this class by yourself by using std::lock , or just use std::lock_guard if you only have one mutex.您可以使用std::lock自己轻松实现此 class ,或者如果您只有一个互斥锁,则只需使用std::lock_guard

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM