Skip to content

[core] Make TROOT::GetFunction more thread-safe - #23222

Closed
vepadulano wants to merge 1 commit into
root-project:masterfrom
vepadulano:core-getfunction-locks
Closed

[core] Make TROOT::GetFunction more thread-safe#23222
vepadulano wants to merge 1 commit into
root-project:masterfrom
vepadulano:core-getfunction-locks

Conversation

@vepadulano

Copy link
Copy Markdown
Member

This method uses a static-initialized atomic boolean modified by a static-initialized immediately-invoked lambda to ensure that either the queried function is returned if available or the ROOT standard functions are initialized before returning the queried function.

This method while theoretically sound has the potential of being wrong because it introduces potential modifications to the fFunctions data member as well as interpreter access via TROOT::ProcessLine without following the locking strategy used in other places of ROOT core.

This commit proposes to introduce the strategy of combining R__[READ,WRITE]_LOCKGUARD(ROOT::gCoreMutex) to ensure thread-safe querying and modification of the ROOT list of functions.

This is related to the various attempts at fixing the cpp11Containers-unorderedMap macro-based test, see #22909 #23021 #23147 #23213

This method uses a static-initialized atomic boolean modified by a
static-initialized immediately-invoked lambda to ensure that either the queried
function is returned if available or the ROOT standard functions are initialized
before returning the queried function.

This method while theoretically sound has the potential of being wrong because
it introduces potential modifications to the fFunctions data member as well as
interpreter access via TROOT::ProcessLine without following the locking strategy
used in other places of ROOT core.

This commit proposes to introduce the strategy of combining
R__[READ,WRITE]_LOCKGUARD(ROOT::gCoreMutex) to ensure thread-safe querying and
modification of the ROOT list of functions.
@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

Test Results

    23 files      23 suites   3d 18h 17m 19s ⏱️
 3 863 tests  3 860 ✅ 3 💤 0 ❌
79 585 runs  79 585 ✅ 0 💤 0 ❌

Results for commit 4adf707.

Comment thread core/base/src/TROOT.cxx
return true;
}();
R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
gROOT->ProcessLine("TF1::InitStandardFunctions(); TF2::InitStandardFunctions(); TF3::InitStandardFunctions();");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why has this to be a call to the interpreter? Can we break the dependency in another way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies, it is not strictly related to these changes, it has always been like that, but it became very visible with this PR...

@vepadulano vepadulano closed this Sep 2, 2026
@vepadulano vepadulano reopened this Sep 2, 2026
@vepadulano

Copy link
Copy Markdown
Member Author

After offline discussion with @pcanal it's unclear how these changes would affect the execution of the test. The function should be thread-safe as it is. Nonetheless, the past two CI runs haven't shown the test failure. Without any more concrete proof that these changes are helping, I will just ago ahead and close the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants