简体   繁体   English

C ++ 17 std :: shared_mutex还没有?

[英]Is C++17 std::shared_mutex not available yet?

Looking at C++ compiler support , it appears that the untimed version of std::shared_mutex is available in GCC 5.0+. 看看C ++编译器支持 ,似乎在GCC 5.0+中可以使用std::shared_mutex的不定时版本。 However, even with gcc version 5.3.0 20151204 (Ubuntu 5.3.0-3ubuntu1~14.04) , and compiling with -std=c++1z , a simple initialization of a shared mutex ends up with: 但是,即使使用gcc version 5.3.0 20151204 (Ubuntu 5.3.0-3ubuntu1~14.04) ,并使用-std=c++1z编译,共享互斥锁的简单初始化最终会:

error: ‘shared_mutex’ in namespace ‘std’ does not name a type
        std::shared_mutex mutex_;

And no, I have already included the proper header: #include <shared_mutex> . 不,我已经包含了正确的标题: #include <shared_mutex>

It can't locate the proper header, because it does not seem to exist. 它找不到合适的标题,因为它似乎不存在。 Actually, the linker uses the library locate at /usr/include/c++/5/shared_mutex , which contains only the implementation of the std::shared_timed_mutex (like the C++14 standard). 实际上,链接器使用位于/usr/include/c++/5/shared_mutex ,它只包含std::shared_timed_mutex的实现(如C ++ 14标准)。

I have installed gcc-5 and g++-5 by adding the repository at ppa:ubuntu-toolchain-r/test and using update-alternatives to properly set up their bins. 我已经通过在ppa:ubuntu-toolchain-r/test添加存储库并使用update-alternatives来正确设置它们的bin来安装gcc-5和g ++ - 5。

Is there something I can do to compile my code correctly using the newest C++17 standard? 有没有什么可以使用最新的C ++ 17标准正确编译我的代码? And probably is a stupid question to ask, but is it too early to start using -std=c++1z even if it should be already supported? 并且可能是一个愚蠢的问题,但即使应该已经支持,开始使用-std=c++1z还为时过早? Because it is supported, right? 因为它受到支持,对吗?

The confusion on cppreference was probably because std::shared_mutex really was added to GCC 5.0, in revision 200134 . cppreference的混淆可能是因为std::shared_mutex确实添加到GCC 5.0, 修订版200134 But that was the early incarnation of that type based on a C++1y draft. 但这是基于C ++ 1y草案的那种类型的早期化身。 In fact it was the timed shared mutex, which was called std::shared_mutex at the time. 实际上它是定时共享的互斥锁,当时称为std::shared_mutex

Before the final C++14 standard was published std::shared_mutex was renamed to std::shared_timed_mutex , and so before the GCC 5.1 release (which is the first release in the 5.x series) the type in libstdc++ was renamed, see revision 207964 . 在发布最终的C ++ 14标准之前, std::shared_mutex被重命名为std::shared_timed_mutex ,因此在GCC 5.1发行版(这是5.x系列中的第一个版本)之前,libstdc ++中的类型被重命名,请参阅修订版207964

So although at one point during the GCC 5.x pre-release phase there was a std::shared_mutex type, it wasn't the C++17 untimed one, and it got renamed before appearing in any official release of GCC. 因此,虽然在GCC 5.x预发布阶段的某个阶段有一个std::shared_mutex类型,但它不是C ++ 17的非定时类型,并且在出现在GCC的任何官方版本之前它已被重命名。

Then, during the development of the GCC 6.x release series the C++1z untimed shared mutex got added, reusing the std::shared_mutex name. 然后,在GCC 6.x发布系列的开发过程中,添加了C ++ 1z untimed共享互斥锁,重用了std::shared_mutex名称。 That's the commit TC linked to in the comments above, revision 224158 . 这是上面评论中修订版224158中提交TC的提交。

So the C++17 untimed shared_mutex was never in any GCC 5.x version. 所以C ++ 17 untimed shared_mutex从未出现在任何GCC 5.x版本中。 For a brief period before the first 5.x release there was a timed one called std::shared_mutex , but in all proper 5.x releases it's called std::shared_timed_mutex . 在第一个5.x版本发布之前的一段时间内,有一个名为std::shared_mutex定时版本,但在所有正确的5.x版本中,它被称为std::shared_timed_mutex

The first release to ship the C++17 untimed one was 6.1 in April 2016, so with any GCC release after that you can use std::shared_mutex (as long as you enable C++17 in the compiler, eg with the -std=gnu++17 or -std=c++17 flag). 2016年4月,第一个发布C ++ 17非定时版本的版本是6.1,所以在之后的任何GCC版本中你可以使用std::shared_mutex (只要在编译器中启用C ++ 17,例如使用-std=gnu++17-std=c++17 flag)。

GCC 5 was released in 2015, so expecting to be able to use C++17 with that version is a bit unrealistic. GCC 5于2015年发布,因此期望能够在该版本中使用C ++ 17有点不切实际。 GCC 6.x and 7.x have pretty good C++1z support (but only based on the current drafts at the time of release, of course). GCC 6.x和7.x具有相当不错的C ++ 1z支持(当然,仅基于发布时的当前草稿)。

follow this link to install/upgrade to the latest version of GCC and G++. 点击此链接安装/升级到最新版本的GCC和G ++。 http://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu http://tuxamito.com/wiki/index.php/Installing_newer_GCC_versions_in_Ubuntu

I have tried it on my ubuntu and successful. 我已经在我的ubuntu上试过并成功了。

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

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