不确定的std::system_error:what():不允许操作
Undeterministic std::system_error: what(): Operation not permitted
我正在尝试运行我的程序,每隔几次运行就会出现一个错误:
terminate called after throwing an instance of 'std::system_error'
what(): Operation not permitted
我的代码在这里可用:https://github.com/Qabrt/turnstiles
gdb输出:
Thread 31 "trivial_test" received signal SIGABRT, Aborted.
[Switching to thread 31 (Thread 0x7fff8a7fc700 (LWP 8716))]
#0 0x00007ffff6e7f83b in raise () from /lib64/libc.so.6
(gdb) bt
#0 0x00007ffff6e7f83b in raise () from /lib64/libc.so.6
#1 0x00007ffff6e81081 in abort () from /lib64/libc.so.6
#2 0x00007ffff78670e5 in __gnu_cxx::__verbose_terminate_handler ()
at /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/libstdc++-v3/libsupc++/vterminate.cc:95
#3 0x00007ffff7864cb6 in __cxxabiv1::__terminate (handler=<optimized out>)
at /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/libstdc++-v3/libsupc++/eh_terminate.cc:47
#4 0x00007ffff7864d01 in std::terminate ()
at /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/libstdc++-v3/libsupc++/eh_terminate.cc:57
#5 0x00007ffff789243f in std::execute_native_thread_routine (__p=0x555555790f80)
at /var/tmp/portage/sys-devel/gcc-7.3.0-r3/work/gcc-7.3.0/libstdc++-v3/src/c++11/thread.cc:91
#6 0x00007ffff7bbd96a in start_thread () from /lib64/libpthread.so.0
#7 0x00007ffff6f4d11f in clone () from /lib64/libc.so.6
g++——版本
g++ (Gentoo 7.3.0-r3 p1.4) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我正在使用-lpthread标志进行编译:
/usr/bin/c++ -Wall -Wunused-function -Wwrite-strings -Wformat -Wformat-security -Wparentheses -Wsequence-point -Wno-system-headers -Werror -Winit-self -g -O0 -fstack-protector-all -D_GLIBXX_DEBUG -D_GLIBXX_DEBUG_PEDANTIC -rdynamic CMakeFiles/trivial_test.dir/trivial_test.cpp.o -o trivial_test ../libturnstile_lib.a -lpthread
如何获取有关该问题的更多信息?
在将函数设置为noexcept后,我能够找到堆栈跟踪,显示我正在对不存在的互斥体的unique_lock调用condition_variable::wait()。只是我调用wait()的Semaphore对象为null。因此,unique_lock抛出的system_error如下https://en.cppreference.com/w/cpp/thread/unique_lock/lock
首先,您需要查明错误是来自std::thread
运行的函数还是来自std::thread
本身。如果函数抛出异常,它将被std::thread
启动器函数捕获,并调用terminate。如果您将函数设为noexcept
,那么terminate
将在被捕获之前被调用,并且您将在堆栈跟踪中看到它是从哪里抛出的(GCC的后续版本不会捕获异常,所以这是自动发生的)。
如果异常来自std::thread
本身,则意味着您的程序已链接到libc.so.6
中pthread_create
的伪定义,而不是libpthread.so
或libpthread.a
中的真实定义
使用ldd
查看您的程序是否链接到共享的libpthread.so
。如果是,则表示您的工具链有问题(应该使用libpthread.so
中的定义,而不是libc.so
中的弱符号)。如果你是静态链接,你可能需要确保libpthread.a
中的所有符号都包含在你的程序中,例如使用:
-Wl,--whole-archive -pthread -Wl,--no-whole-archive
注意:您应该使用-pthread
而不是-lpthread
,因为这允许GCC确保它被放置在链接命令中的正确位置。
- 为什么 Clang 不允许"and"作为函数名称?
- 不允许在向量中添加更多元素
- std::带有自定义缓冲区的 iostream 不允许我写入
- Visual Studio 2017 不允许我创建 C++ 专用模板
- 返回时不允许隐式转换
- 为什么 c++(g++) 不允许模板返回类型和函数名称之间有空格?
- 为什么 c++ 不允许(自动)强制转换?
- 为什么 c++11 不允许使用自动
- 为什么不允许成员函数和非成员函数之间的函数重载?
- 不确定的std::system_error:what():不允许操作
- 当对象的当前状态不允许在其上进行操作时,要投掷哪个例外
- Qt 创建者,跟踪:不允许操作.什么是永久解决方案
- 什么会导致罕见的 lchown() 失败:不允许操作
- 为线程设置新优先级时不允许操作
- glm::vec2 不允许操作
- 如果 ssl::stream<tcp::socket 有挂起的操作,我是否不允许删除它>?
- 奇怪的异常抛出分配:不允许操作
- Qt数组中的C++不允许传入或操作值
- 谷歌核心转储程序返回不允许的操作
- 启用多线程来使用std::thread:不允许操作