From: Armin Hasitzka Date: Wed, 20 Sep 2017 19:51:18 +0000 (+0200) Subject: [TSan] Unlock fastpath when checking domains_to_finalize (#5598) X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=mono.git;a=commitdiff_plain;h=c7e322d704332360ffdb32aa18d722b3f93cb8cc [TSan] Unlock fastpath when checking domains_to_finalize (#5598) [TSan] Unlock fastpath when checking domains_to_finalize I understand that the affected line is a fastpath which seems absolutely fine to me as it is properly checked later. It is, however, rightfully, detected as a data race by Clang's ThreadSanitizer. I would, therefore, suggest using `UnlockedReadPointer ()` to mark this race as known + accepted. --- diff --git a/mono/metadata/gc.c b/mono/metadata/gc.c index 3c78b6153c2..3e0fcb0953e 100644 --- a/mono/metadata/gc.c +++ b/mono/metadata/gc.c @@ -44,6 +44,7 @@ #include #include #include +#include #ifndef HOST_WIN32 #include @@ -780,7 +781,7 @@ finalize_domain_objects (void) DomainFinalizationReq *req = NULL; MonoDomain *domain; - if (domains_to_finalize) { + if (UnlockedReadPointer ((gpointer)&domains_to_finalize)) { mono_finalizer_lock (); if (domains_to_finalize) { req = (DomainFinalizationReq *)domains_to_finalize->data; diff --git a/mono/utils/unlocked.h b/mono/utils/unlocked.h index dedcc4e73cf..406b686cfeb 100644 --- a/mono/utils/unlocked.h +++ b/mono/utils/unlocked.h @@ -122,4 +122,11 @@ UnlockedReadBool (gboolean *src) return *src; } +MONO_UNLOCKED_ATTRS +gpointer +UnlockedReadPointer (volatile gpointer *src) +{ + return *src; +} + #endif /* _UNLOCKED_H_ */