<div dir="ltr">Thanks!<div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Hans</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jun 6, 2023 at 4:22 PM Fred J. Tydeman <<a href="mailto:tydeman@tybor.com">tydeman@tybor.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 6 Jun 2023 11:35:26 -0700 Hans Boehm wrote:<br>
><br>
>>  Could you give a specific example illustrating your concern? I'm<br>
>currently confused.<br>
<br>
Perhaps:<br>
<br>
#define LOCK(S) while( ++S != 1){ --S ; }<br>
#define UNLOCK(S) --S;<br>
<br>
static _Atomic int state = 0;<br>
static _Atomic int done = 0;<br>
static double d = 0.0;<br>
<br>
int main( void ){<br>
.... start 2nd thread ...<br>
.... this is 1st thread ...<br>
  LOCK(state);<br>
  done = 1;<br>
  d /= 0.0;     /* without function call, this can be delayed after UNLOCK */<br>
  UNLOCK(state);<br>
...<br>
    }<br>
<br>
... 2nd thread ...<br>
  for(int div_done=0; 0==div_done;){<br>
    LOCK(state);<br>
    if( done != 0 ){<br>
      div_done = 1;<br>
    }<br>
    UNLOCK(state);<br>
  }<br>
  d = 1.0;      /* if d /= 0.0; is delayed, this could be concurrent  */<br>
                /* d could be 1.0 or NaN or unknown value */<br>
  if( 1.0 != d ){<br>
...<br>
<br>
<br>
<br>
---<br>
Fred J. Tydeman        Tydeman Consulting<br>
<a href="mailto:tydeman@tybor.com" target="_blank">tydeman@tybor.com</a>      Testing, numerics, programming<br>
+1 (702) 608-6093      Vice-chair of INCITS/C (ANSI "C")<br>
Sample C17+FPCE tests: <a href="http://www.tybor.com" rel="noreferrer" target="_blank">http://www.tybor.com</a><br>
Savers sleep well, investors eat well, spenders work forever.<br>
</blockquote></div>