gpt4 book ai didi

multithreading - timed_mutex 不会在 Cygwin 4.8.2 ('timed_mutex' 下编译,命名空间 'std' 没有命名类型)

转载 作者:行者123 更新时间:2023-12-01 03:48:28 27 4
gpt4 key购买 nike

我的文件 test8.cpp

#include<thread>
#include<mutex>
#include<chrono>

std::mutex mutex;
std::timed_mutex timed_mutex;

当我编译这段代码时
g++ -std=c++11 -pthread -c test8.cpp

它告诉我

timed_mutex in namespace 'std' does not name a type



我在Cygwin64下编译,gcc版本4.8.2

screenshot

================================================== ================

@乔纳森·韦克利

enter image description here

最佳答案

timed_mutex类型仅在平台支持时才定义。 GCC 中的预处理器条件 <mutex>是:

#ifdef _GLIBCXX_USE_C99_STDINT_TR1

如果平台定义了一个可用的 <stdint.h>标题,和
#if _GTHREAD_USE_MUTEX_TIMEDLOCK

如果宏 _POSIX_TIMEOUTS 被定义由 <unistd.h> 定义为正值标题。

如果未定义第一个宏,则您将无法使用 std::mutex要么,所以似乎只有第二个宏是未定义的,这意味着 Cygwin 的 Pthreads 实现不支持超时功能。

用于检查超时功能的测试类似于:
#include <unistd.h>
// In case of POSIX threads check _POSIX_TIMEOUTS.
#if (defined(_PTHREADS) \
&& (!defined(_POSIX_TIMEOUTS) || _POSIX_TIMEOUTS <= 0))
#error
#endif
int main() { }

您可以尝试在 Cygwin 上编译它,然后自己检查宏。如果 Cygwin 确实支持超时功能,请 report a GCC bug所以我们可以制作 timed_mutex在 Cygwin 上工作。

编辑:对于 GCC 6,我添加了一个 alternative implementation of std::timed_mutex 对于未定义 _POSIX_TIMEOUTS 的平台。我不知道这对 Cygwin 是否有帮助。

关于multithreading - timed_mutex 不会在 Cygwin 4.8.2 ('timed_mutex' 下编译,命名空间 'std' 没有命名类型),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25015790/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com