fix(rewrite): skip fork/adopt injection for detached thread spawns#113
Merged
rocketman-code merged 1 commit intomainfrom Feb 25, 2026
Merged
fix(rewrite): skip fork/adopt injection for detached thread spawns#113rocketman-code merged 1 commit intomainfrom
rocketman-code merged 1 commit intomainfrom
Conversation
All free-function spawns (std::thread::spawn, rayon::spawn, tokio::spawn) require F: Send + 'static. When SpanContext is moved into such a closure it drops on the child thread, where the STACK thread-local is empty -- silently losing CPU time attribution. Introduce FORK_TRIGGER_FUNCTIONS (scope, scope_fifo, join) to limit fork/adopt injection to scoped concurrency boundaries only. Detached spawn() calls are now detected and skipped in both find_concurrency_pattern (no fork injected) and inject_adopt_in_concurrency_closures (no adopt injected, no recursion into closure body). Closes #103
b163e93 to
6ed122d
Compare
This was referenced Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
std::thread::spawn,rayon::spawn): they requireF: 'static, and SpanContext dropping on the child thread silently loses CPU attribution dataFORK_TRIGGER_FUNCTIONSconstant containing only scoped concurrency functions (scope,scope_fifo,join) that safely support fork/adopts.spawn()method calls inside scope bodies continue working viarecurse_closure_body_for_spawnsTest plan
skips_fork_for_thread_spawn-- verifies no fork/adopt injected forstd::thread::spawnskips_fork_for_short_path_thread_spawn-- verifies barespawn()also skippedno_concurrency_for_thread_spawn-- verifies no concurrency reported for detached spawnmixed_scope_and_thread_spawn-- verifies exactly 1 adopt (ins.spawn) when bothrayon::scopeandstd::thread::spawnpresentstd::thread::spawnrepro project builds and runs (was E0597/E0373 before)rayon::scoperepro project still builds with fork/adopt injectedCloses #103