gpt4 book ai didi

multithreading - gcc 支持 unique_locks 吗?

转载 作者:行者123 更新时间:2023-12-01 05:42:38 24 4
gpt4 key购买 nike

我想在我的代码中使用线程,并认为即将到来的 C++0x 扩展会很方便,因为它们最终会成为一个标准。这似乎是面向 future 的,无需使用像 boost::thread 这样的额外库。
不幸的是,我找不到有关 gcc 当前支持哪些线程特性的有用信息。我正在使用似乎不起作用的 unique_locks 。这是链接器的输出:

.build_debug/src/core/simulator.o: In function `Simulator::start(int, int, int, int)':
simulator.cpp:(.text+0x1fc): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::resume()':
simulator.cpp:(.text+0x351): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::pause()':
simulator.cpp:(.text+0x417): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'
.build_debug/src/core/simulator.o: In function `Simulator::stop()':
simulator.cpp:(.text+0x4cd): undefined reference to `_ZSt4lockISt11unique_lockISt5mutexES2_IEEvRT_RT0_DpRT1_'

有人理解这些信息吗?我猜他们指的是 unique_locks 的用法。但是为什么会出现这些错误呢?

我的源代码类似于这个:
std::unique_lock<std::mutex> lkIntra(intraMtx, std::defer_lock);
std::unique_lock<std::mutex> lkInter(interMtx, std::defer_lock);
std::lock(lkIntra, lkInter);

编辑:我试图用 gcc 4.3.X 和 4.4.5 编译它。接头是 g++ 4.3、4.4 和 4.5。

EDIT2:我只是尝试使用与 std 线程等效的 boost。添加编译器标志“-lboost_thread”后,编译工作。没有它,链接过程会导致类似的错误消息。现在我想知道在使用标准线程时是否需要做类似的事情(我已经尝试过“-lpthread”)。

最佳答案

目前G++开发版本支持:http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00729.html

4.5.1 版本似乎没有(至少,对于我在 Mac OS Intel 上)。

关于multithreading - gcc 支持 unique_locks 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4454121/

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