From 50fed0475f13e0a5868e25cc29746ac3fa32efbd Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Mon, 7 Nov 2016 15:58:36 +0000 Subject: [OpenMP] Enable ThreadSanitizer to check OpenMP programs This patch allows ThreadSanitizer (Tsan) to verify OpenMP programs. It means that no false positive will be reported by Tsan when verifying an OpenMP programs. This patch introduces annotations within the OpenMP runtime module to provide information about thread synchronization to the Tsan runtime. In order to enable the Tsan support when building the runtime, you must enable the TSAN_SUPPORT option with the following environment variable: -DLIBOMP_TSAN_SUPPORT=TRUE The annotations will be enabled in the main shared library (same mechanism of OMPT). Patch by Simone Atzeni and Joachim Protze! Differential Revision: https://reviews.llvm.org/D13072 llvm-svn: 286115 --- openmp/runtime/src/z_Linux_util.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'openmp/runtime/src/z_Linux_util.c') diff --git a/openmp/runtime/src/z_Linux_util.c b/openmp/runtime/src/z_Linux_util.c index 6c51301d1bf..b3c3e80083b 100644 --- a/openmp/runtime/src/z_Linux_util.c +++ b/openmp/runtime/src/z_Linux_util.c @@ -59,6 +59,8 @@ #include #include +#include "tsan_annotations.h" + /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ @@ -1609,6 +1611,7 @@ __kmp_suspend_initialize( void ) static void __kmp_suspend_initialize_thread( kmp_info_t *th ) { + ANNOTATE_HAPPENS_AFTER(&th->th.th_suspend_init_count); if ( th->th.th_suspend_init_count <= __kmp_fork_count ) { /* this means we haven't initialized the suspension pthread objects for this thread in this instance of the process */ @@ -1618,6 +1621,7 @@ __kmp_suspend_initialize_thread( kmp_info_t *th ) status = pthread_mutex_init( &th->th.th_suspend_mx.m_mutex, & __kmp_suspend_mutex_attr ); KMP_CHECK_SYSFAIL( "pthread_mutex_init", status ); *(volatile int*)&th->th.th_suspend_init_count = __kmp_fork_count + 1; + ANNOTATE_HAPPENS_BEFORE(&th->th.th_suspend_init_count); }; } -- cgit v1.2.3