Max*_*FPS 8 c++ crash multithreading pthreads qt-creator
在 Qt Creator 中运行此自动生成的最小(无 qt)C++ 应用程序时,为什么/sysdeps/unix/sysv/linux/x86_64/clone.S在 Ubuntu 20.10 上的(反汇编)“ test %rax,%rax ”处因 SIGSTOP 崩溃4.14.2 DEBUG 模式下:
#include <iostream>
#include <thread>
void foo()
{
}
int main()
{
std::thread t(foo); // Crash happens after stepping over this line
t.join();
std::cout << "All good!" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
调用栈
1 clone clone.S 78 0x7f28abaef215
2 ?? allocatestack.c 313 0x7f28abbc94b0
3 ?? 0x7f28ab881640
4 ??
Run Code Online (Sandbox Code Playgroud)
allocatestack.c 的反汇编程序停止于:
pthread_create.c:
0x7f28abbc94b0 f3 0f 1e fa endbr64
Run Code Online (Sandbox Code Playgroud)
clone.S 的反汇编程序在“test %rax,%rax”处停止:
50 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891e0 f3 0f 1e fa endbr64
52 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891e4 <+ 4> 48 c7 c0 ea ff ff ff mov $0xffffffffffffffea,%rax
53 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891eb <+ 11> 48 85 ff test %rdi,%rdi
54 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891ee <+ 14> 74 3d je 0x7f2f1638922d <clone+77>
55 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891f0 <+ 16> 48 85 f6 test %rsi,%rsi
56 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891f3 <+ 19> 74 38 je 0x7f2f1638922d <clone+77>
59 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891f5 <+ 21> 48 83 ee 10 sub $0x10,%rsi
60 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891f9 <+ 25> 48 89 4e 08 mov %rcx,0x8(%rsi)
64 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f163891fd <+ 29> 48 89 3e mov %rdi,(%rsi)
67 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389200 <+ 32> 48 89 d7 mov %rdx,%rdi
68 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389203 <+ 35> 4c 89 c2 mov %r8,%rdx
69 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389206 <+ 38> 4d 89 c8 mov %r9,%r8
70 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389209 <+ 41> 4c 8b 54 24 08 mov 0x8(%rsp),%r10
71 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f1638920e <+ 46> b8 38 00 00 00 mov $0x38,%eax
76 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389213 <+ 51> 0f 05 syscall
78 [1] in ../sysdeps/unix/sysv/linux/x86_64/clone.S
0x7f2f16389215 <+ 53> 48 85 c0 test %rax,%rax
Run Code Online (Sandbox Code Playgroud)
CMakeLists.txt
cmake_minimum_required(VERSION 3.5)
project(testThread LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# These 3 lines were added by me to the auto generated CMakeLists.txt
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE) # Ensures that -pthread is added to the compile flags
find_package(Threads REQUIRED)
add_executable(testThread main.cpp)
target_link_libraries(testThread Threads::Threads)
Run Code Online (Sandbox Code Playgroud)
CMake输出
Running /usr/bin/cmake -S /home/myhome/testThread -B /home/myhome/testThread/build-debug '-GCodeBlocks - Ninja' -DCMAKE_BUILD_TYPE:String=Debug -DQT_QMAKE_EXECUTABLE:STRING= -DCMAKE_PREFIX_PATH:STRING= -DCMAKE_C_COMPILER:STRING=/usr/bin/gcc -DCMAKE_CXX_COMPILER:STRING=/usr/bin/g++ in /home/myhome/testThread/build-debug.
-- The CXX compiler identification is GNU 10.2.0
-- Check for working CXX compiler: /usr/bin/g++
-- Check for working CXX compiler: /usr/bin/g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
QT_QMAKE_EXECUTABLE
-- Build files have been written to: /home/myhome/testThread/build-debug
Elapsed time: 00:00.
Run Code Online (Sandbox Code Playgroud)
CMake 构建输出
17:24:26: Running steps for project testThread...
17:24:26: Starting: "/usr/bin/cmake" --build . --target all --verbose
[1/2 3.9/sec] /usr/bin/g++ -g -pthread -std=gnu++11 -MD -MT CMakeFiles/testThread.dir/main.cpp.o -MF CMakeFiles/testThread.dir/main.cpp.o.d -o CMakeFiles/testThread.dir/main.cpp.o -c ../main.cpp
[2/2 6.9/sec] : && /usr/bin/g++ -g CMakeFiles/testThread.dir/main.cpp.o -o testThread -pthread && :
17:24:26: The process "/usr/bin/cmake" exited normally.
17:24:26: Elapsed time: 00:00.
Run Code Online (Sandbox Code Playgroud)
g++版本
~$ g++ --version
g++ (Ubuntu 10.2.0-13ubuntu1) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
Run Code Online (Sandbox Code Playgroud)
到目前为止,我尝试创建这个最小的示例,而不使用 ccache 并使用空的构建文件夹,但问题仍然存在。我没主意了。
非常感谢帮助!
更新1
在 Qt Creator 中以 RELEASE 模式运行效果良好
按照评论中的建议从终端运行效果很好
g++ -pthread -o testThread main.cpp
./测试线程
使用 gdb 从终端运行效果很好
$ gdb ./testThread
GNU gdb (Ubuntu 9.2-0ubuntu2) 9.2
版权所有 (C) 2020 自由软件基金会, Inc.
从 ./testThread 读取符号...
(gdb)r
启动程序:testThread
[启用使用libthread_db进行线程调试]
使用主机 libthread_db 库“/lib/x86_64-linux-gnu/libthread_db.so.1”。
[新线程0x7ffff7a51640 (LWP 5946)]
[线程 0x7ffff7a51640 (LWP 5946) 已退出]
都好!
【下级1(进程5942)正常退出】
(gdb)
更新2
似乎问题与 Qt Creator 有关。有两种解决方法。
将其添加到“调试助手自定义”中:
处理 SIGSTOP 通过 nostop noprint
| 归档时间: |
|
| 查看次数: |
1118 次 |
| 最近记录: |