[英]std::thread.join() SIGSEGV on Mac OS under Valgrind
以下簡單代碼(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);
}
// 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
這是Valgrind的一個錯誤。 主要錯誤報告可以在這里找到: https : //bugs.kde.org/show_bug.cgi?id = 349128
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.