我有一些线程池的代码,它已经在我的 Ubuntu 机器上运行了相当长一段时间了。该项目是一个 CMake 项目,我相信它使用最新版本的 g++ 作为编译器。
我只是尝试在 Mac 上运行代码,CMake 尝试使用 AppleClang 12.0.0.12000032,我遇到了
libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
Run Code Online (Sandbox Code Playgroud)
AppleClang 丢失了std::shared_mutex吗std::mutex?这些是 c++17 功能。我需要做些什么才能在这台 Mac 上启用 c++17 吗?我确实提到我的文件中需要它CMakeLists.txt。
这是完整的构建输出:
(base) clare.obrien.brown@Clares-Air build % cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/clare.obrien.brown/ssme/build
(base) clare.obrien.brown@Clares-Air build % make
Scanning dependencies of target ssme_test
[ 16%] Building CXX object test/CMakeFiles/ssme_test.dir/test-main.cpp.o
[ 33%] Building CXX object test/CMakeFiles/ssme_test.dir/test_ada_pmmh_mvn.cpp.o
[ 50%] Building CXX object test/CMakeFiles/ssme_test.dir/test_parameters.cpp.o
In file included from /Users/clare.obrien.brown/ssme/test/test_parameters.cpp:5:
/Users/clare.obrien.brown/ssme/include/ssme/parameters.h:333:58: warning: unused parameter 'trans_p' [-Wunused-parameter]
float_t null_trans<float_t>::log_jacobian(const float_t& trans_p)
^
1 warning generated.
[ 66%] Building CXX object test/CMakeFiles/ssme_test.dir/test_thread_pool.cpp.o
/Users/clare.obrien.brown/ssme/test/test_thread_pool.cpp:13:46: warning: unused parameter 'obs_data' [-Wunused-parameter]
static double d(param_t nums, obs_data_t obs_data) {
^
/Users/clare.obrien.brown/ssme/test/test_thread_pool.cpp:54:45: warning: unused parameter 'od' [-Wunused-parameter]
[](param_t nums, obs_data_t od) -> double{
^
/Users/clare.obrien.brown/ssme/test/test_thread_pool.cpp:82:40: warning: unused parameter 'ydata' [-Wunused-parameter]
double d(param_t theta, obs_data_t ydata) {
^
3 warnings generated.
[ 83%] Building CXX object test/CMakeFiles/ssme_test.dir/test_utils.cpp.o
[100%] Linking CXX executable ssme_test
[100%] Built target ssme_test
(base) clare.obrien.brown@Clares-Air build % cd ../test
(base) clare.obrien.brown@Clares-Air test % ../build/test/ssme_test
libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
libc++abi.dylib: terminating with uncaught exception of type std::__1::system_error: mutex lock failed: Invalid argument
zsh: abort ../build/test/ssme_test
Run Code Online (Sandbox Code Playgroud)
这是抛出异常的地方:https://github.com/llvm/llvm-project/blob/main/libcxx/src/mutex.cpp#L35
当对尚未构造或已被破坏的.lock()对象进行调用时,通常会发生这种情况。当在返回之前或之后mutex访问具有静态存储持续时间的互斥体时,可能会发生这种情况。您需要检查启动或关闭逻辑,以确保其生命周期超过尝试使用它的客户端的生命周期。main()main()mutex
/Applications/Utilities/Console.app 可以为您提供抛出未捕获的异常时应用程序的堆栈跟踪。这可能有助于您的调试工作。编译-g可以为堆栈跟踪提供更好的调试信息。
| 归档时间: |
|
| 查看次数: |
15885 次 |
| 最近记录: |