c++ - 为什么我的 C++ 程序在删除 cout 语句时崩溃并返回代码 11?

标签 c++ multithreading cout

在我的 C++ 项目中,我遇到了一个非常奇怪的问题。当我删除 某个日志语句 (cout) 时,它会崩溃并显示退出代码 11

This answer指向一个解释退出代码 11(实际上是 EAGAIN)的源代码,其中包含以下语句:

The system lacked the necessary resources to create another thread, or the system-imposed limit on the total number of threads in a process PTHREAD_THREADS_MAX would be exceeded.

但我很确定不要在我的代码中创建任何额外的线程(至少不要明确地创建)。那么为什么会出现错误,为什么当我使用日志语句时错误消失了?

作为引用,我将发布代码,但它当然完全脱离了上下文,基本上唯一相关的行是带有日志语句的行。

 PayloadRegionMapper(string mappingTechniqueName, string configPath = "")
    : payload(PAYLOAD), config(Config(configPath)) {

    cout << "construct PayloadRegionMapper" << endl; // if commented out, my program crashes....

    frames = generateFrames();
    setMappingTechnique(mappingTechniqueName);
}

最佳答案

使用调试器运行程序,然后在崩溃发生后回溯。 使用 bt 和 frame 命令,您可以了解程序在崩溃情况下的行为。

gdb <executable>

.....<crash happened>

bt
<It will give you the stack frame >

frame <frame number>

Then look for the values and memory area there. 

关于c++ - 为什么我的 C++ 程序在删除 cout 语句时崩溃并返回代码 11?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802614/

相关文章:

c++ - Cout 不打印指向内存的内容

java - 混合代码( native 、托管): how does it (technically) interoperate?

c++ - 使用动态规划找到最大数量

multithreading - 使用EF4和锁定的表中的唯一值

java - 服务器和客户端之间的简单连接。客户端发送消息,服务器正确接收消息。但是当服务器尝试回复时什么也不起作用?

c++ - cout << 实际上是如何工作的?

c++ - 创建一个窗口应用程序,每 10 分钟执行一次特定操作

c++ - 在C++中计算汉明序列(一个只有2、3和5作为分隔符的数字序列)

ios - 在加载 View 之前从 iCloud 加载文档

c++ - 为什么 std::cout 以相同的小数精度打印 float 、 double 和长 double ?