This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PR18457] Don't require rtld lock to compute DTV addr for static TLS
- From: Torvald Riegel <triegel at redhat dot com>
- To: Andreas Schwab <schwab at linux-m68k dot org>
- Cc: Alexandre Oliva <aoliva at redhat dot com>, libc-alpha at sourceware dot org
- Date: Thu, 04 Jun 2015 22:37:54 +0200
- Subject: Re: [PR18457] Don't require rtld lock to compute DTV addr for static TLS
- Authentication-results: sourceware.org; auth=none
- References: <orvbf5ffyt dot fsf at livre dot home> <1433326788 dot 21461 dot 81 dot camel at triegel dot csb> <ora8whexn9 dot fsf at livre dot home> <m27frj8m70 dot fsf at linux-m68k dot org>
On Thu, 2015-06-04 at 18:36 +0200, Andreas Schwab wrote:
> Alexandre Oliva <aoliva@redhat.com> writes:
>
> >>> +static int running = 1;
> >>> + while (running)
> >
> >> That's a data race with the modification do_end, or isn't it?
>
> There is no way this can go wrong.
Of course there is.
"running" is static, and it's easy for the compiler to see that it
doesn't escape in this program (ie, it's not visible outside of this
TU). Thus, the printf in the while loop will never modify it.
You promised the compiler a data-race-free program. Thus, you promised
that "running" won't ever change during the execution of "test_run" (ie,
no other thread and no other TU will ever do it). Therefore, the
compiler can hoist the load of "running" outside of the loop:
register = running;
while (register)
printf("...");
And your program won't terminate as a result. The compiler can even do
the following transformation, figuring out that the register content
doesn't change:
if (running)
while (1)
printf("...");
As another data point, think about why we have "atomic_forced_read" in
include/atomic.h. All it does is to actually do read a variable. Why
would we need this if code like in your test can't go wrong?