std :: thread.join()在Mac OS下的Valgrind下的SIGSEGV [英] std::thread.join() SIGSEGV on Mac OS under Valgrind

查看:395
本文介绍了std :: thread.join()在Mac OS下的Valgrind下的SIGSEGV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  #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);
}
//等待线程完成
for(int tt = 0; tt< 10; ++ tt){
printf \\\
,tt);
std :: cout.flush();
threads [tt] .join();
printf(Joined%d\\\
,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上不能运行,失败with:

  == 47544 ==以信号11(SIGSEGV)的默认动作结束的进程
== 47544 = =访问不在映射区域内的地址0x700008F31C3E
== 47544 ==在0x10052E37F:_pthread_find_thread(在/usr/lib/system/libsystem_pthread.dylib)
== 47544 == by 0x100530D52:_pthread_join_cleanup /usr/lib/system/libsystem_pthread.dylib)
== 47544 == by 0x100530C63:pthread_join(在/usr/lib/system/libsystem_pthread.dylib)
== 47544 == by 0x100057E94:std :: __ 1 :: thread :: join()(在/usr/lib/libc++.1.dylib)
== 47544 == by 0x100001BB1:main(in ./vgtest)



任何想法为什么这是失败的(然后只在OSX上)?



Valgrind-3.11.0,OSX 10.11.3

解决方案

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


The following simple code (C++ 11) will run just find on Mac OS and Linux:

#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;
}

However, wrap execution in Valgrind:

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

...and it now works on Linux, but not on Mac OSX, failing with:

==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)

Any ideas why this is failing (and then only on OSX)?

Valgrind-3.11.0, OSX 10.11.3

解决方案

This is a bug in Valgrind. Master bug report can be found here: https://bugs.kde.org/show_bug.cgi?id=349128

这篇关于std :: thread.join()在Mac OS下的Valgrind下的SIGSEGV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆