From 6935b70ffc030113249ce80cc76734ec83d72dba Mon Sep 17 00:00:00 2001 From: Dariusz Sciebura Date: Thu, 21 Nov 2024 07:48:56 +0000 Subject: [PATCH] core/logging: Fix data race on log_prefix In ofi_get_core_info, which is supposed to be thread safe ("Multiple threads may call fi_getinfo simultaneously, without any requirement for serialization."), a global variable 'log_prefix' is modified, which may lead to a data race. Changing the variable to a thread local one, fixes that problem. Signed-off-by: Dariusz Sciebura --- include/ofi.h | 2 +- src/common.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/ofi.h b/include/ofi.h index 9661a7553d9..6239a6b1f3c 100644 --- a/include/ofi.h +++ b/include/ofi.h @@ -320,7 +320,7 @@ struct ofi_filter { extern struct ofi_filter prov_log_filter; extern struct fi_provider core_prov; -extern const char *log_prefix; +extern _Thread_local const char *log_prefix; void ofi_create_filter(struct ofi_filter *filter, const char *env_name); void ofi_free_filter(struct ofi_filter *filter); diff --git a/src/common.c b/src/common.c index 0d641ac74a1..4ae2d411afd 100644 --- a/src/common.c +++ b/src/common.c @@ -2429,4 +2429,4 @@ size_t ofi_vrb_speed(uint8_t speed, uint8_t width) } /* log_prefix is used by fi_log and by prov/util */ -const char *log_prefix = ""; +_Thread_local const char *log_prefix = "";