janestreet / janestreet/magic-trace
stop indicator does not work in multi-threaded application
- Dominant language
- OCaml
- Stars
- 6.3k
- Forks
- 209
- PR merge metrics
- No merged PRs in 30d
Description
We have a simple reproducer:
```cpp
///usr/bin/env -S clang++ -O0 "$0" -o /tmp/demo && exec /tmp/demo "$@"
#include
#include
#include
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.
Contributor guide
Research direction
Start by compiling and running the supplied C++ reproducer with and without the extra argument, then trace how magic_trace_stop_indicator is handled for the main thread versus the child thread. The fix is done when the indicator triggers reliably in both execution modes, including the multi-threaded case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100