[Cfp-interest 2774] Re: CFP review of NB comments on CD2 - 20230602

Hans Boehm boehm at acm.org
Tue Jun 6 21:13:34 PDT 2023


Thanks!

It sounds like we're reading that paragraph differently. Like Jim, I read
it as only saying something about when the floating point exception flag
could be set. And that can presumably only be read by a function call.

The assignment to d in main can clearly not be moved out of the critical
section. The UNLOCK on the main thread happens-before the LOCK in thread 2,
and thus the test of d in the second thread can only see the immediately
preceding assignment.

Hans

On Tue, Jun 6, 2023 at 4:22 PM Fred J. Tydeman <tydeman at tybor.com> wrote:

> On Tue, 6 Jun 2023 11:35:26 -0700 Hans Boehm wrote:
> >
> >>  Could you give a specific example illustrating your concern? I'm
> >currently confused.
>
> Perhaps:
>
> #define LOCK(S) while( ++S != 1){ --S ; }
> #define UNLOCK(S) --S;
>
> static _Atomic int state = 0;
> static _Atomic int done = 0;
> static double d = 0.0;
>
> int main( void ){
> .... start 2nd thread ...
> .... this is 1st thread ...
>   LOCK(state);
>   done = 1;
>   d /= 0.0;     /* without function call, this can be delayed after UNLOCK
> */
>   UNLOCK(state);
> ...
>     }
>
> ... 2nd thread ...
>   for(int div_done=0; 0==div_done;){
>     LOCK(state);
>     if( done != 0 ){
>       div_done = 1;
>     }
>     UNLOCK(state);
>   }
>   d = 1.0;      /* if d /= 0.0; is delayed, this could be concurrent  */
>                 /* d could be 1.0 or NaN or unknown value */
>   if( 1.0 != d ){
> ...
>
>
>
> ---
> Fred J. Tydeman        Tydeman Consulting
> tydeman at tybor.com      Testing, numerics, programming
> +1 (702) 608-6093      Vice-chair of INCITS/C (ANSI "C")
> Sample C17+FPCE tests: http://www.tybor.com
> Savers sleep well, investors eat well, spenders work forever.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.oakapple.net/pipermail/cfp-interest/attachments/20230606/01498bca/attachment.htm>


More information about the Cfp-interest mailing list