From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 4B67D396C816; Fri, 14 May 2021 10:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B67D396C816 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-794] TSAN: add new test X-Act-Checkin: gcc X-Git-Author: Michael de Lang X-Git-Refname: refs/heads/master X-Git-Oldrev: fe108dad32f521c4f924a397f11c63f86519e183 X-Git-Newrev: 80b4ce1a5190ebe764b1009afae57dcef45f92c2 Message-Id: <20210514101027.4B67D396C816@sourceware.org> Date: Fri, 14 May 2021 10:10:27 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 14 May 2021 10:10:27 -0000 https://gcc.gnu.org/g:80b4ce1a5190ebe764b1009afae57dcef45f92c2 commit r12-794-g80b4ce1a5190ebe764b1009afae57dcef45f92c2 Author: Michael de Lang Date: Fri May 14 12:09:45 2021 +0200 TSAN: add new test gcc/testsuite/ChangeLog: * g++.dg/tsan/pthread_cond_clockwait.C: New test. Diff: --- gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C new file mode 100644 index 00000000000..82d6a5c8329 --- /dev/null +++ b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C @@ -0,0 +1,31 @@ +// Test pthread_cond_clockwait not generating false positives with tsan +// { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && pthread } } } +// { dg-options "-fsanitize=thread -lpthread" } + +#include + +pthread_cond_t cv; +pthread_mutex_t mtx; + +void *fn(void *vp) { + pthread_mutex_lock(&mtx); + pthread_cond_signal(&cv); + pthread_mutex_unlock(&mtx); + return NULL; +} + +int main() { + pthread_mutex_lock(&mtx); + + pthread_t tid; + pthread_create(&tid, NULL, fn, NULL); + + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + ts.tv_sec += 10; + pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts); + pthread_mutex_unlock(&mtx); + + pthread_join(tid, NULL); + return 0; +}