Skip to content

[DEBUG — do not merge] localize Windows-only native crash - #62

Closed
jemus42 wants to merge 20 commits into
masterfrom
debug-win-crash
Closed

[DEBUG — do not merge] localize Windows-only native crash#62
jemus42 wants to merge 20 commits into
masterfrom
debug-win-crash

Conversation

@jemus42

@jemus42 jemus42 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Temporary instrumentation to localize the Windows-only native crash seen on #61 (run 29271102587): hardened utils::Matrix::operator[] bounds checks (unchecked first index, off-by-one flat guard) + per-file child-process test harness with markers that survive a native crash. Will be closed once the culprit is identified.

🤖 Generated with Claude Code

MHiabu and others added 20 commits August 8, 2025 15:02
…, split_decay_rate, delete_leaves ) and different behaviour of split_try
…, threading.

Fixed bug in split_structure="leaves" mode; changed behaviour of  split_structure="res_trees" mode to fit description.
Update documentation and examples for clarity.
…_try' of github.com:PlantedML/randomPlantedForest into new-max_candidates-split_decay_rate-delete_leaves-split_try
Two changes to turn the silent Windows crash into actionable output:

- src/include/helper.hpp: harden utils::Matrix::operator[] — bounds-check
  every dimension (the first index was previously unchecked) and use >= for
  the flat-index guard (previously > allowed reading one past the end).
  Out-of-bounds access now throws with the offending dimension and index.

- tests/testthat.R: TEMPORARY harness that runs each test file in its own
  R child process with BEGIN/END markers, so the crashing file is visible
  in testthat.Rout even when the child dies natively.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Crash localized to test-rpf-reproducibility.R, exit 0xC0000005 during
rpf(nthreads = 2). Matrix bisects: thread count, ntrees, deterministic,
purify, fit-vs-predict, repeat fits.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Matrix v1 result: ALL nthreads>=2 fits crash at fit1 (0xC0000005), even
ntrees=1 (single worker thread, no concurrency); nthreads=1 passes.
So: any create_tree_family on a non-main thread dies on Windows.

v2: fprintf(stderr) stage markers in training.cpp thread lambda and
create_tree_family (leaves path), gated behind RPF_DEBUG env var;
matrix reduced to (1) instrumented single-worker fit, (2) serial fit +
threaded purify mode 2, (3) serial fit + threaded purify mode 1.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Root cause of the Windows-only crash (0xC0000005) in threaded fit:
the namespace-scope thread_local std::vector<std::vector<int>>
tls_working_bin_id registers an emutls destructor when touched by a
worker thread. On Windows (MinGW/Rtools, package DLL loaded via
LoadLibrary), running that destructor at std::thread exit crashes the
process. Proven via marker instrumentation: worker completed all work
([thr 0] exit printed), process died during thread teardown; threaded
purify, which touches no non-trivial TLS, passes on Windows.

Fix follows the existing tls_rng_ptr pattern: TLS holds only a POD
pointer; the buffer is a stack-owned local in create_tree_family.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jemus42

jemus42 commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator Author

Root cause found and fix verified: thread_local std::vector (tls_working_bin_id) registers an emutls destructor that crashes at std::thread exit on Windows (MinGW, DLL via LoadLibrary). Replacing it with a trivially-destructible TLS pointer to a stack-owned buffer makes windows-latest pass (run of bf83921). Fix will land on #61.

@jemus42 jemus42 closed this Jul 13, 2026
@jemus42
jemus42 deleted the debug-win-crash branch July 13, 2026 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants