Skip to content

Fix thread-unsafe lazy initialization in ExpDeproj::mass()#205

Merged
The9Cat merged 2 commits intoSphericalExactfrom
copilot/sub-pr-199
Feb 25, 2026
Merged

Fix thread-unsafe lazy initialization in ExpDeproj::mass()#205
The9Cat merged 2 commits intoSphericalExactfrom
copilot/sub-pr-199

Conversation

Copy link

Copilot AI commented Feb 25, 2026

ExpDeproj::mass() used lazy initialization guarded only by a size check, making it unsafe for concurrent calls before the grid was populated.

Changes

  • include/ExpDeproj.H: Move initialize() call into the constructor, eliminating lazy init entirely.
  • exputil/ExpDeproj.cc: Remove the now-redundant mv.size() == 0 guard from mass().
// Before
ExpDeproj(int n=4000) : ngrid(n) {}  // grid populated on first mass() call

double ExpDeproj::mass(double R) {
  if (mv.size() == 0) initialize();  // race condition under concurrent access
  ...
}

// After
ExpDeproj(int n=4000) : ngrid(n) { initialize(); }  // grid ready at construction

double ExpDeproj::mass(double R) {
  // no init check needed
  ...
}

Grid is now computed once at construction time, before any thread can invoke mass().


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: The9Cat <25960766+The9Cat@users.noreply.github.com>
Copilot AI changed the title [WIP] Work in progress on deprojection feedback for exponential surface density Fix thread-unsafe lazy initialization in ExpDeproj::mass() Feb 25, 2026
@The9Cat The9Cat marked this pull request as ready for review February 25, 2026 19:09
@The9Cat The9Cat merged commit aeccbd3 into SphericalExact Feb 25, 2026
@The9Cat The9Cat deleted the copilot/sub-pr-199 branch February 25, 2026 19:09
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