Serialize build_callable under a global lock to prevent segfaults in threaded usage#227
Merged
Conversation
Serialise build_callable under a ReentrantLock so that concurrent threads cannot race during first-time callable IR generation and cache population, which caused segfaults in threaded Particle Gibbs sampling on Julia 1.10.
Copilot
AI
changed the title
[WIP] Fix Julia 1.10 segfault in threaded PG due to concurrent Libtask callable generation
Serialize Jun 5, 2026
build_callable under a global lock to prevent segfaults in threaded usage
- Move `build_callable_lock` above the docstring so the docstring attaches to `build_callable` again (fixes Documenter `docs_block`/`missing_docs`) - Wrap the `misty_closure` call to stay within blue style's margin at its new indentation (fixes JuliaFormatter check) - Update the SMC test to FlexiChains' `(niters, nchains)` layout: the chain count is `size(chain, 2)`, not `size(chain, 3)` Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Libtask.jl documentation for PR #227 is available at: |
yebai
reviewed
Jun 5, 2026
yebai
reviewed
Jun 5, 2026
sunxd3
reviewed
Jun 14, 2026
seed_id! mutates the shared global _id_count, the same structure the ID() constructor mutates during IR derivation. Calling it from TapedTask ran it outside build_callable_lock, so it could race with ID generation on another thread and crash. Move it into the cache-miss branch of build_callable, under the lock, alongside the ID() calls it pairs with. Addresses review feedback from @sunxd3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
sunxd3
approved these changes
Jun 15, 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.
On Julia 1.10, concurrent threads can race through
build_callableduring first-time callable IR generation, causing segfaults in threaded Particle Gibbs sampling. The existingGlobalMCCachelock only protectssetindex!, not the full IR derivation + compilation pipeline.build_callablebody in aReentrantLockso only one thread performs callable IR generation at a timeFix #226