Fix race condition in cpp metric tests. (#9058)

This commit is contained in:
Jiaming Yuan
2023-04-21 05:24:10 +08:00
committed by GitHub
parent a5cd2412de
commit b908680bec

View File

@@ -217,7 +217,7 @@ struct EvalError {
} }
} }
const char *Name() const { const char *Name() const {
static std::string name; static thread_local std::string name;
if (has_param_) { if (has_param_) {
std::ostringstream os; std::ostringstream os;
os << "error"; os << "error";
@@ -315,7 +315,7 @@ struct EvalTweedieNLogLik {
<< "tweedie variance power must be in interval [1, 2)"; << "tweedie variance power must be in interval [1, 2)";
} }
const char *Name() const { const char *Name() const {
static std::string name; static thread_local std::string name;
std::ostringstream os; std::ostringstream os;
os << "tweedie-nloglik@" << rho_; os << "tweedie-nloglik@" << rho_;
name = os.str(); name = os.str();