From: Bernd Edlinger <bernd.edlinger@hotmail.de>
To: Janne Blomqvist <blomqvist.janne@gmail.com>
Cc: Thomas Koenig <tkoenig@netcologne.de>,
"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [patch, libfortran] Fix thead sanitizer issue with libgfortran
Date: Sun, 01 Oct 2017 09:02:00 -0000 [thread overview]
Message-ID: <304c58c9-3c15-380a-a748-2fe4b792d2d1@hotmail.de> (raw)
Hi,
I think this might be a false positive tsan warning.
Maybe tsan does not see why a desctructor function
can not execute before the last detached thread
terminates.
I created a small test case that receives a warning
which is similar to the one you tried to fix with your
patch:
cat test.c
#include <stdio.h>
#include <pthread.h>
int test;
static void *
t1(void* p)
{
printf("t1\n");
test = 1;
return NULL;
}
static void __attribute__((destructor))
t2 (void)
{
test = 2;
printf("t2\n");
}
int
main()
{
pthread_t t;
pthread_attr_t a;
pthread_attr_init(&a);
pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED);
pthread_create(&t, &a, t1, NULL);
pthread_attr_destroy(&a);
return 0;
}
gcc -Wall -fsanitize=thread test.c
./a.out
t1
t2
==================
WARNING: ThreadSanitizer: data race (pid=3564)
Write of size 4 at 0x00000060107c by thread T1:
#0 t1 <null> (a.out+0x00000040088e)
Previous write of size 4 at 0x00000060107c by main thread:
#0 t2 <null> (a.out+0x0000004008c6)
#1 <null> <null> (ld-linux-x86-64.so.2+0x0000000108d9)
Location is global 'test' of size 4 at 0x00000060107c
(a.out+0x00000060107c)
Thread T1 (tid=3566, running) created by main thread at:
#0 pthread_create
../../../../gcc-trunk/libsanitizer/tsan/tsan_interceptors.cc:900
(libtsan.so.0+0x00000002914e)
#1 main <null> (a.out+0x00000040092e)
SUMMARY: ThreadSanitizer: data race
(/home/ed/gnu/gcc-test/a.out+0x40088e) in t1
==================
ThreadSanitizer: reported 1 warnings
The warning goes away when the main function explicitly
joins the thread t1.
That is what I do with all my threads whenever possible,
maybe there is a way how you could explicitly join
all running threads?
Bernd.
next reply other threads:[~2017-10-01 9:02 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-01 9:02 Bernd Edlinger [this message]
2017-10-01 13:41 ` Thomas Koenig
2017-10-01 14:23 ` Bernd Edlinger
2017-10-01 16:54 ` Thomas Koenig
-- strict thread matches above, loose matches on Subject: below --
2017-09-28 17:29 Thomas Koenig
2017-09-29 6:03 ` Thomas Koenig
2017-09-29 8:04 ` Janne Blomqvist
2017-09-29 18:53 ` Thomas Koenig
2017-10-01 7:42 ` Janne Blomqvist
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=304c58c9-3c15-380a-a748-2fe4b792d2d1@hotmail.de \
--to=bernd.edlinger@hotmail.de \
--cc=blomqvist.janne@gmail.com \
--cc=fortran@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=tkoenig@netcologne.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).