This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RE: [PATCH] Fix sporadic failure in g++.dg/tsan/aligned_vs_unaligned_race.C
- From: Bernd Edlinger <bernd dot edlinger at hotmail dot de>
- To: Mike Stump <mikestump at comcast dot net>
- Cc: Jakub Jelinek <jakub at redhat dot com>, "H.J. Lu" <hjl dot tools at gmail dot com>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Dmitry Vyukov <dvyukov at google dot com>
- Date: Tue, 6 Jan 2015 10:08:22 +0100
- Subject: RE: [PATCH] Fix sporadic failure in g++.dg/tsan/aligned_vs_unaligned_race.C
- Authentication-results: sourceware.org; auth=none
- References: <DUB118-W421A4A9D8D09CBAF5103DAE45A0 at phx dot gbl>,<3C12133C-DABF-40FA-94F7-9DB785F6E914 at comcast dot net>,<DUB118-W292D09896C48BED7B29B14E45A0 at phx dot gbl>,<DUB118-W8F5E63DE36A8DB2DA1DF6E45B0 at phx dot gbl>,<623A5348-6FC9-4F7B-A9BC-B2B098AF7D37 at comcast dot net>,<20150104191658 dot GK1667 at tucnak dot redhat dot com>,<DUB118-W450ACE7162969EFB27F817E45B0 at phx dot gbl>,<8E43F8AA-96BA-47A3-A886-C058459B4108 at comcast dot net>,<DUB118-W286F157F7B8B1EE05ED51FE4580 at phx dot gbl>,<E67B07D7-6ABA-48C1-B58B-B804144D91C2 at comcast dot net>,<D86529BC-DB94-481A-AE60-913D7E2B8D7F at comcast dot net>,<DUB118-W1E901D082BACEDE02A5E8E4590 at phx dot gbl>
Hi Mike,
after some hours of sleep I realized that your step function can do something very interesting,
(which you already requested previously):
That is: create a race condition that is _always_ at 100% missed by tsan:
cat lib.c
/* { dg-do compile } */
/* { dg-options "-O2 -fno-sanitize=all" } */
static volatile int serial = 0;
void step (int i)
{
while (__atomic_load_n (&serial, __ATOMIC_ACQUIRE) != i - 1);
__atomic_store_n (&serial, i, __ATOMIC_RELEASE);
}
cat tiny_race.c
/* { dg-shouldfail "tsan" } */
#include <pthread.h>
void step(int);
int Global;
void *Thread1(void *x) {
step (1);
Global = 42;
step (3);
return x;
}
int main() {
pthread_t t;
pthread_create(&t, 0, Thread1, 0);
step (2);
Global = 43;
step (4);
pthread_join(t, 0);
return Global;
}
/* { dg-output "WARNING: ThreadSanitizer: data race.*(\n|\r\n|\r)" } */
Bernd.