Skip to content

MVA generated code is not thread-safe (Follow-up from "PrLongLivedTracking: remove use of `static` in MLP")

The following discussion from !1053 (merged) should be addressed:

  • @graven started a discussion:

    Aside: PrLongLivedTracking is not reproducible 'as is' when run multithreaded. The number of tracks produced varies from run to run. As the code it self looks thread-safe (after I changed the counters to the new Gaudi counters), I tried the following:

    @@ -485,7 +492,12 @@ LHCb::Tracks PrLongLivedTracking::operator()(const LHCb::Tracks& InputTracks) co
             m_debugTool->tuneFinalMVA( track.track(), trueTrack, vals);
           }
     
    -      const double mvaVal = m_mvaReader->GetMvaValue( vals );
    +      auto mva = [&](auto& v) {
    +         std::lock_guard<std::mutex> guard(mvaMx);
    +         return m_mvaReader->GetMvaValue( v );
    +      };
    +
    +      const double mvaVal = mva( vals );
           track.setMVAVal( mvaVal );
     
           foundBestCand = foundBestCand || mvaVal > 0.05;
    

    where mvaMx is a mutex defined in the global scope. And lo-and-behold, the result becomes reproducible. So the TMVA generated code is not thread-safe in more ways... (how can just asking the evaluate an (already initialized) MVA be not thread-safe???)