We have a simple reproducer:
///usr/bin/env -S clang++ -O0 "$0" -o /tmp/demo && exec /tmp/demo "$@"
#include <iostream>
#include <fstream>
#include <thread>
using namespace std;
extern "C" {
void __attribute__((noinline)) __attribute__((used)) magic_trace_stop_indicator() { }
}
void task() {
ifstream r;
ofstream w;
r.open("/dev/zero", ios::binary);
w.open("/dev/null", ios::binary);
char buf[4096] = {0};
for (int i = 0; i >= 0; i++)
{
r.read(buf, sizeof(buf));
w.write(buf, sizeof(buf));
if (i % 100 == 0) {
magic_trace_stop_indicator();
}
}
}
int main(int argc, char *argv[])
{
if (argc > 1) {
std::cout << "running in thread" << std::endl;
std::thread t1(task);
t1.join();
} else {
std::cout << "running in main" << std::endl;
task();
}
}
magic_trace_stop_indicator can be triggered reliably in main thread, but not in child thread.
We have a simple reproducer:
magic_trace_stop_indicatorcan be triggered reliably in main thread, but not in child thread.