仅在多核上运行时出现分段错误

发布于 2024-08-11 21:36:10 字数 262 浏览 4 评论 0原文

我正在使用一个 C++ 库,它是多线程的,并且可以使用变量设置工作线程的数量。该库使用 pthread。当我在使用 3 个或更多线程的四核计算机上运行作为库测试提供的应用程序时,就会出现问题。应用程序退出并出现分段错误运行时错误。当我尝试在库的某些部分插入一些跟踪“cout”时,问题得到解决,应用程序正常完成。 当在单核机器上运行时,无论使用多少个线程,应用程序都会正常完成。

我怎样才能找出问题出在哪里?

这是一种同步错误吗?我怎样才能找到它?有什么工具可以用来检查代码吗?

I am using a c++ library that is meant to be multi-threaded and the number of working threads can be set using a variable. The library uses pthreads. The problem appears when I run the application ,that is provided as a test of library, on a quad-core machine using 3 threads or more. The application exits with a segmentation fault runtime error. When I try to insert some tracing "cout"s in some parts of library, the problem is solved and application finishes normally.
When running on single-core machine, no matter what number of threads are used, the application finishes normally.

How can I figure out where the problem seam from?

Is it a kind of synchronization error? how can I find it? is there any tool I can use too check the code ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

情魔剑神 2024-08-18 21:36:10

听起来你正在使用Linux(你提到了pthreads)。您是否考虑过运行valgrind

Valgrind 具有用于检查数据竞争条件 (helgrind) 和内存问题 (memcheck) 的工具。 Valgrind 可能是在调试模式下发现这样的错误而不需要产生发布模式产生的崩溃。

Sounds like you're using Linux (you mention pthreads). Have you considered running valgrind?

Valgrind has tools for checking for data race conditions (helgrind) and memory problems (memcheck). Valgrind may be to find such an error in debug mode without needing to produce the crash that release mode produces.

゛时过境迁 2024-08-18 21:36:10

一些一般性的调试建议。

  1. 确保您的构建具有符号(使用 -g 进行编译)。该选项与其他构建选项正交(即使用符号构建的决定与优化级别无关)。
  2. 获得符号后,请仔细查看发生段错误的调用堆栈。为此,首先确保您的环境配置为生成核心文件(ulimit -c unlimited),然后在崩溃后,在调试器中加载程序/核心(gdb /path/to/prog /path/to/core) 。一旦您知道代码的哪一部分导致了崩溃,您就可以更好地了解出了什么问题。

Some general debugging recommendations.

  1. Make sure your build has symbols (compile with -g). This option is orthogonal to other build options (i.e. the decision to build with symbols is independent of the optimization level).
  2. Once you have symbols, take a close look at the call stack of where the seg fault occurs. To do this, first make sure your environment is configured to generate core files (ulimit -c unlimited) and then after the crash, load the program/core in the debugger (gdb /path/to/prog /path/to/core). Once you know what part of your code is causing the crash, that should give you a better idea of what is going wrong.
睡美人的小仙女 2024-08-18 21:36:10

您正在陷入竞争状态。
多个线程在同一资源上交互。
可能的罪魁祸首有很多,但如果没有消息来源,我们所说的任何事情都只是猜测。

您想要创建一个核心文件;然后使用核心文件调试应用程序。这会将调试器设置为应用程序崩溃时的状态。这将允许您检查变量/寄存器等。

如何执行此操作很大程度上取决于您的系统。

快速谷歌揭示了这一点:

http://www.codeguru。 com/forum/archive/index.php/t-299035.html

希望这有帮助。

You are running into a race condition.
Where multiple threads are interacting on the same resource.
There are a whole host of possible culprits, but without the source anything we say is a guess.

You want to create a core file; then debug the application with the core file. This will set up the debugger to the state of the application at the point it crashed. This will allow you to examin the variables/registers etc.

How to do this will very depending on your system.

A quick Google revealed this:

http://www.codeguru.com/forum/archive/index.php/t-299035.html

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文