Serialize build_callable under a global lock to prevent segfaults in threaded usage#227
Open
Copilot wants to merge 4 commits into
Open
Serialize build_callable under a global lock to prevent segfaults in threaded usage#227Copilot wants to merge 4 commits into
build_callable under a global lock to prevent segfaults in threaded usage#227Copilot wants to merge 4 commits into
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
| # the valid world age to be very strictly just the current age allows the | ||
| # compiler to do more inlining and other optimisation. | ||
| unoptimised_ir = set_valid_world!(unoptimised_ir, world_age) | ||
| lock(build_callable_lock) |
Member
There was a problem hiding this comment.
It's difficult to unit-test this, as it is a stochastic crash caused by racing. Intensive A/B testing verifies this is indeed the fix.
yebai
reviewed
Jun 5, 2026
| chain = sample(StableRNG(468), model, SMC(), 100; progress=false) | ||
| @test size(chain, 1) == 100 | ||
| @test size(chain, 3) == 1 | ||
| @test size(chain, 2) == 1 |
Member
There was a problem hiding this comment.
This is due to a change in FlexiChains and fails on main too.
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