Skip to content

Commit 10ea292

Browse files
committed
[df] Ensure there is code to JIT before calling the interpreter
In an explicit multithreading scenario inside the `RLoopManager::Jit` method, a thread might move the global string with the code to JIT into its own function stack while another thread might still believe that string is not empty. This would make the other thread call `InterpreterCalc` with an empty string which would eventually lead to an exception. Check for the string emptiness twice, once at the beginning of the function, then again after taking the write lock so that if another thread already moved the string then the current thread will not continue with JITting.
1 parent 86c17c0 commit 10ea292

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Diff for: tree/dataframe/src/RLoopManager.cxx

+13-10
Original file line numberDiff line numberDiff line change
@@ -805,18 +805,21 @@ void RLoopManager::CleanUpTask(TTreeReader *r, unsigned int slot)
805805
/// This method also clears the contents of GetCodeToJit().
806806
void RLoopManager::Jit()
807807
{
808-
{
809-
R__READ_LOCKGUARD(ROOT::gCoreMutex);
810-
if (GetCodeToJit().empty()) {
811-
R__LOG_INFO(RDFLogChannel()) << "Nothing to jit and execute.";
812-
return;
813-
}
808+
R__READ_LOCKGUARD(ROOT::gCoreMutex);
809+
if (GetCodeToJit().empty()) {
810+
R__LOG_INFO(RDFLogChannel()) << "Nothing to jit and execute.";
811+
return;
814812
}
815813

816-
const std::string code = []() {
817-
R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
818-
return std::move(GetCodeToJit());
819-
}();
814+
R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
815+
// Check again if another thread has already cleared the global string
816+
// with the code to JIT. Without this check, we could end up calling
817+
// InterpreterCalc with an empty string, which would raise an exception.
818+
if (GetCodeToJit().empty()) {
819+
R__LOG_INFO(RDFLogChannel()) << "Nothing to jit and execute.";
820+
return;
821+
}
822+
const std::string code = std::move(GetCodeToJit());
820823

821824
TStopwatch s;
822825
s.Start();

0 commit comments

Comments
 (0)