From: Ivan Maidanski Date: Mon, 30 Oct 2017 22:09:56 +0000 (+0300) Subject: Workaround TSan false positive in invoke_finalizers X-Git-Tag: v8.0.0~529 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=57f22ff97d7961784ad7e93578558990ddd74e2e;p=gc Workaround TSan false positive in invoke_finalizers * finalize.c [THREADS && !THREAD_SANITIZER] (GC_invoke_finalizers): Do not compare bytes_freed_before to GC_bytes_freed without the lock; add comment. * include/private/gc_priv.h (_GC_arrays._finalizer_bytes_freed): Replace "mem." to "memory" in a comment. --- diff --git a/finalize.c b/finalize.c index 0c39b54d..aaed8d4e 100644 --- a/finalize.c +++ b/finalize.c @@ -1224,7 +1224,15 @@ GC_API int GC_CALL GC_invoke_finalizers(void) /* finalizable. Otherwise it should not matter. */ } /* bytes_freed_before is initialized whenever count != 0 */ - if (count != 0 && bytes_freed_before != GC_bytes_freed) { + if (count != 0 +# if defined(THREADS) && !defined(THREAD_SANITIZER) + /* A quick check whether some memory was freed. */ + /* The race with GC_free() is safe to be ignored */ + /* because we only need to know if the current */ + /* thread has deallocated something. */ + && bytes_freed_before != GC_bytes_freed +# endif + ) { LOCK(); GC_finalizer_bytes_freed += (GC_bytes_freed - bytes_freed_before); UNLOCK(); diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 7fc977d7..e10bcfde 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1224,7 +1224,7 @@ struct _GC_arrays { /* since last collection. */ word _finalizer_bytes_freed; /* Bytes of memory explicitly deallocated while */ - /* finalizers were running. Used to approximate mem. */ + /* finalizers were running. Used to approximate memory */ /* explicitly deallocated by finalizers. */ ptr_t _scratch_end_ptr; ptr_t _scratch_last_end_ptr;