This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PR18457] Don't require rtld lock to compute DTV addr for static TLS


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?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]