简体   繁体   中英

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. My app is a console multi-threaded app, and uses 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.

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:

#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"

The application is 32 bits, debug. 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.

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.

The standard library is located in dinkumware64 for 32-bit programs as well, so you should be looking there.

Problem is that scoped_lock is missing from the standard library.

You can easily implement this class by yourself by using std::lock , or just use std::lock_guard if you only have one mutex.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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