Add missing lock

I cherrypicked this from Philippe Canal's fix on the official ROOT 5.34.00 branch.
This should fix Vincenzo Innocente's discovered problem with TFormula.