Optimization of conditional access to globals: thread-unsafe?
David Miller
davem@davemloft.net
Mon Oct 29 07:43:00 GMT 2007
From: Darryl Miles <darryl-mailinglists@netbauds.net>
Date: Mon, 29 Oct 2007 04:53:49 +0000
> What are the issues with "speculative loads" ?
The conditional might be protecting whether the pointer is valid and
can be dereferenced at all.
int *counter;
void foo(int counter_is_valid)
{
if (counter_is_valid)
(*counter)++;
}
And in another module that GCC can't see when compiling foo():
extern int *counter;
int main(void)
{
int a = 0;
foo(0);
counter = &a;
foo(1);
return 0;
}
More information about the Gcc
mailing list