【问题标题】:TBB allocation issuing a kill signalTBB 分配发出终止信号
【发布时间】:2019-07-20 15:05:36
【问题描述】:

我的 C++ 程序(在 Mac OS 上运行)被杀死了。使用调试器运行后,我获得以下信息:

Process 90937 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGKILL
frame #0: 0x000000010001fc50 captureISO`tbb::interface9::internal::start_for<WDutils::Parallel::details::blocked_range_terminating<unsigned long>, (anonymous namespace)::simulations::sampleSome(bool)::$_2, tbb::auto_partitioner const>::run_body(WDutils::Parallel::details::blocked_range_terminating<unsigned long>&) [inlined] tbb::concurrent_vector<(anonymous namespace)::simulations::initialCondition, tbb::cache_aligned_allocator<(anonymous namespace)::simulations::initialCondition> >::push_back(this=0x00007fff5fbfebd0)::simulations::initialCondition const&) at concurrent_vector.h:846 [opt]
   843         iterator push_back( const_reference item )
   844         {
   845             push_back_helper prolog(*this);
-> 846             new(prolog.internal_push_back_result()) T(item);
   847             return prolog.return_iterator_and_dismiss();
   848         }
   849

因此,kill 信号似乎是由tbb::concurrent_vector&lt;&gt; 内的分配发出的。但是,tbb::concurrent_vector::push_back() 的文档和 operator new 的文档都没有建议这样的操作。

这是TBB 的未记录行为(宁愿杀死正在运行的进程,因为 TBB 无法正确处理异常)?我怎样才能知道以及如何避免这种情况?

【问题讨论】:

    标签: c++ c++11 new-operator tbb sigkill


    【解决方案1】:

    您可能需要优化算法以使用更少的内存。

    我不知道 macOS 是如何处理内存分配的,但是在 Linux 上,如果你使用太多内存,“OOM Killer”会发送 SIGKILL 信号。

    【讨论】:

    • @Walter 希望您不必完全重新考虑内存分配,而是有一种更简单的方法可以在操作系统终止应用程序之前捕获失败的新内存或处理/释放内存。失控的分配模式(如果这是实际发生的情况) - stackoverflow.com/a/6834029/475228
    • 我现在明白内存分配是个问题。但是,这不应该导致操作员new 抛出异常而不是运行时系统终止进程吗?
    • @Walter 没有必要,这就是“过度使用”的意义所在。基本上,在大多数 Linux 上,您可以毫无问题地分配 4TB 内存,因为内核不会立即提供物理存储来支持该虚拟内存。它基本上“希望”你不会访问你分配的大部分内存。 Macos 上的行为似乎没有记录在案,但 this 帖子表明 macos 确实过度使用。
    • 就是这样。将关键细节整合到投票的答案中(目前还没有完全回答问题)
    猜你喜欢
    • 2023-03-28
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-18
    相关资源
    最近更新 更多