【问题标题】:std::thread.join() SIGSEGV on Mac OS under ValgrindValgrind 下 Mac OS 上的 std::thread.join() SIGSEGV
【发布时间】:2016-04-12 14:27:21
【问题描述】:

以下简单代码 (C++ 11) 将在 Mac OS 和 Linux 上运行 just find:

#include <thread>
#include <chrono>
#include <iostream>

void threadFunction() {
    for (int cc=0; cc < 10000000; ++cc) {
        if (cc%1000000 == 0) {
            std::this_thread::sleep_for(std::chrono::milliseconds(200));
        }
    }
}


int main(int argc, char **argv) {
    std::thread threads[10];
    for (int tt = 0; tt < 10; ++tt) {
        threads[tt] = std::thread(threadFunction);
    }
    // Wait for the threads to complete
    for (int tt = 0; tt < 10; ++tt) {
        printf("About to join %d\n", tt);
        std::cout.flush();
        threads[tt].join();
        printf("Joined %d\n", tt);
        std::cout.flush();
    }
    return 0;
}

但是,在 Valgrind 中包装执行:

valgrind --leak-check=full --show-reachable=no --track-fds=yes --error-exitcode=1 --track-origins=yes ./theexecutable

...它现在可以在 Linux 上运行,但不能在 Mac OSX 上运行,失败:

==47544== Process terminating with default action of signal 11 (SIGSEGV)
==47544==  Access not within mapped region at address 0x700008F31C3E
==47544==    at 0x10052E37F: _pthread_find_thread (in /usr/lib/system/libsystem_pthread.dylib)
==47544==    by 0x100530D52: _pthread_join_cleanup (in /usr/lib/system/libsystem_pthread.dylib)
==47544==    by 0x100530C63: pthread_join (in /usr/lib/system/libsystem_pthread.dylib)
==47544==    by 0x100057E94: std::__1::thread::join() (in /usr/lib/libc++.1.dylib)
==47544==    by 0x100001BB1: main (in ./vgtest)

任何想法为什么会失败(然后仅在 OSX 上)?

Valgrind-3.11.0、OSX 10.11.3

【问题讨论】:

标签: c++ macos valgrind


【解决方案1】:

这是 Valgrind 中的一个错误。主要错误报告可以在这里找到:https://bugs.kde.org/show_bug.cgi?id=349128

【讨论】:

    猜你喜欢
    • 2017-04-16
    • 2011-11-21
    • 2012-07-01
    • 2016-05-20
    • 1970-01-01
    • 2016-08-07
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多