This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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: Program that segfaults with -Ofast


On 8 January 2018 at 09:13, Andrew Haley wrote:
> On 07/01/18 21:27, Christer Solskogen wrote:
>> Fixed!
>>
>> Wanna know something funny?
>> Having a printf fixed the segfault. Without it, it would crash.
>> So the workaround in read_kickstart (memory.cpp) was to add
>> "volatile int i" instead of "int i".
>>
>> Just one simple printf("Value of i: %d\n", i); was enough to not segfault.
>
> That's probably not the real fix, unless you have another thread accessing
> i.

And even if another thread is accessing that variable, making it
volatile does not make the code correct.

It's possible that the bug is now hidden by the combination of
volatile and a sequence point introduced by calling printf, but it's
still a bug to access a shared variable without atomic ops, see
http://isvolatileusefulwiththreads.com/


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