Allan , >>he might as well go traditional you mean using the locks ?
Thank you ~Umesh On Sat, Jul 21, 2018 at 4:20 AM, Allan Sandfeld Jensen <li...@carewolf.com> wrote: > On Samstag, 21. Juli 2018 00:21:48 CEST Jonathan Wakely wrote: >> On Fri, 20 Jul 2018 at 23:06, Allan Sandfeld Jensen wrote: >> > On Freitag, 20. Juli 2018 14:19:12 CEST Umesh Kalappa wrote: >> > > Hi All , >> > > >> > > We are looking at the C sample i.e >> > > >> > > extern int i,j; >> > > >> > > int test() >> > > { >> > > while(1) >> > > { i++; >> > > >> > > j=20; >> > > >> > > } >> > > return 0; >> > > } >> > > >> > > command used :(gcc 8.1.0) >> > > gcc -S test.c -O2 >> > > >> > > the generated asm for x86 >> > > >> > > .L2: >> > > jmp .L2 >> > > >> > > we understand that,the infinite loop is not deterministic ,compiler >> > > is free to treat as that as UB and do aggressive optimization ,but we >> > > need keep the side effects like j=20 untouched by optimization . >> > > >> > > Please note that using the volatile qualifier for i and j or empty >> > > asm("") in the while loop,will stop the optimizer ,but we don't want >> > > do that. >> > >> > But you need to do that! If you want changes to a variable to be >> > observable in another thread, you need to use either volatile, >> >> No, volatile doesn't work for that. >> > It does, but you shouldn't use for that due to many other reasons (though the > linux kernel still does) But if the guy wants to code primitive without using > system calls or atomics, he might as well go traditional > > 'Allan > >