Re: Are there real use cases with the Java access modes?

Alex Otenko via Concurrency-interest <[email protected]> Sat, 24 Jul 2021 06:18:18 +0100
Newsgroups gmane.comp.java.jsr.166-concurrency
Message-ID <CANkgWKj9SQiTh5h20XTrHDHxBQ8b-WHa43tSO9vUH5Z=5o=NqA@mail.gmail.com>
--===============4917203794213877586==
Content-Type: multipart/alternative; boundary="0000000000009594be05c7d7a697"

--0000000000009594be05c7d7a697
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Yes. It depends on what you think an empty loop is.

char odd(int x){
  for(;;){
    x++;
    if(!x) return 1;
    x++;
  }
}

Oops, this can tell you that 2 is an odd number. But you can prove x never
becomes 0 for even inputs. How's that for the least astonishment?

Alex

On Fri, 23 Jul 2021, 21:02 Gregg Wonderly, <[email protected]> wrote:

>
>
> On Jul 23, 2021, at 2:31 PM, Alex Otenko via Concurrency-interest <
> [email protected]> wrote:
> On Fri, 23 Jul 2021, 16:24 Gregg Wonderly, <[email protected]> wrote:
>
>>
>>
>> > On Jul 23, 2021, at 4:14 AM, Andrew Dinn via Concurrency-interest <
>> [email protected]> wrote:
>> >
>> > On 23/07/2021 04:36, Gregg Wonderly via Concurrency-interest
>> >
>> >> Truly, it takes pretty extreme expertise and experience to truly
>> >> understand how to [use Java to] do concurrent programming.
>> >
>> > Let's just note that if you take out the bracketed phrase that
>> statement still remains true.
>>
>> I added that phrase because my experience with concurrency inside of Jav=
a
>> programs is the largest exposure I have.  But that is dated compared to =
my
>> use of multi-threaded application in C/C++ that I=E2=80=99ve recently be=
en involved
>> in.  In those cases, there is no worry about non-volatile hoisting doesn=
=E2=80=99t
>> occur at all.
>
>
> I am sorry to burst your bubble...
>
> http://eel.is/c++draft/intro.progress
>
> Quote:
> The implementation may assume that any thread will eventually do one of
> the following:
>
>    - (1.1) <http://eel.is/c++draft/intro.progress#1.1>
>    terminate,
>    - (1.2) <http://eel.is/c++draft/intro.progress#1.2>
>    make a call to a library I/O function,
>    - (1.3) <http://eel.is/c++draft/intro.progress#1.3>
>    perform an access through a volatile glvalue, or
>    - (1.4) <http://eel.is/c++draft/intro.progress#1.4>
>    perform a synchronization operation or an atomic operation.
>    <http://eel.is/c++draft/intro.progress#1.sentence-1>
>
> [*Note 1 <http://eel.is/c++draft/intro.progress#note-1>*:
> This is intended to allow compiler transformations such as *removal of
> empty loops, even when termination cannot be proven.
> <http://eel.is/c++draft/intro.progress#1.sentence-2>*
>  =E2=80=94 *end note*]
>
>
> Empty loop optimizations have been around for a long time.  I suppose you
> may be trying to tell me that there=E2=80=99s all kinds of places in all =
kinds of
> ways that your code may disappear or executed differently than you expect=
?
>
> Gregg Wonderly
>
>

--0000000000009594be05c7d7a697
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Yes. It depends on what you think an empty loop is.<div d=
ir=3D"auto"><br></div><div dir=3D"auto">char odd(int x){</div><div dir=3D"a=
uto">=C2=A0 for(;;){</div><div dir=3D"auto">=C2=A0 =C2=A0 x++;</div><div di=
r=3D"auto">=C2=A0 =C2=A0 if(!x) return 1;</div><div dir=3D"auto">=C2=A0 =C2=
=A0 x++;</div><div dir=3D"auto">=C2=A0 }</div><div dir=3D"auto">}</div><div=
 dir=3D"auto"><br></div><div dir=3D"auto">Oops, this can tell you that 2 is=
 an odd number. But you can prove x never becomes 0 for even inputs. How&#3=
9;s that for the least astonishment?=C2=A0</div><div dir=3D"auto"><br></div=
><div dir=3D"auto">Alex</div></div><br><div class=3D"gmail_quote"><div dir=
=3D"ltr" class=3D"gmail_attr">On Fri, 23 Jul 2021, 21:02 Gregg Wonderly, &l=
t;<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><b=
lockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px =
#ccc solid;padding-left:1ex"><div style=3D"word-wrap:break-word;line-break:=
after-white-space"><br><div><br><blockquote type=3D"cite"><div>On Jul 23, 2=
021, at 2:31 PM, Alex Otenko via Concurrency-interest &lt;<a href=3D"mailto=
:[email protected]" target=3D"_blank" rel=3D"noreferrer">c=
[email protected]</a>&gt; wrote:</div><div><div dir=3D"auto=
" style=3D"font-family:Helvetica;font-size:12px;font-style:normal;font-vari=
ant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;t=
ext-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;text=
-decoration:none"><div><div class=3D"gmail_quote"><div dir=3D"ltr" class=3D=
"gmail_attr">On Fri, 23 Jul 2021, 16:24 Gregg Wonderly, &lt;<a href=3D"mail=
to:[email protected]" target=3D"_blank" rel=3D"noreferrer">[email protected]</a>&gt=
; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:=
rgb(204,204,204);padding-left:1ex"><br><br>&gt; On Jul 23, 2021, at 4:14 AM=
, Andrew Dinn via Concurrency-interest &lt;<a href=3D"mailto:concurrency-in=
[email protected]" rel=3D"noreferrer noreferrer" target=3D"_blank">concu=
[email protected]</a>&gt; wrote:<br>&gt;<span>=C2=A0</span><br>=
&gt; On 23/07/2021 04:36, Gregg Wonderly via Concurrency-interest<br>&gt;<s=
pan>=C2=A0</span><br>&gt;&gt; Truly, it takes pretty extreme expertise and =
experience to truly<br>&gt;&gt; understand how to [use Java to] do concurre=
nt programming.<br>&gt;<span>=C2=A0</span><br>&gt; Let&#39;s just note that=
 if you take out the bracketed phrase that statement still remains true.<br=
><br>I added that phrase because my experience with concurrency inside of J=
ava programs is the largest exposure I have.=C2=A0 But that is dated compar=
ed to my use of multi-threaded application in C/C++ that I=E2=80=99ve recen=
tly been involved in.=C2=A0 In those cases, there is no worry about non-vol=
atile hoisting doesn=E2=80=99t occur at all.=C2=A0<span>=C2=A0</span></bloc=
kquote></div></div><div dir=3D"auto"><br></div><div dir=3D"auto">I am sorry=
 to burst your bubble...</div><div dir=3D"auto"><br></div><div dir=3D"auto"=
><a href=3D"http://eel.is/c++draft/intro.progress" target=3D"_blank" rel=3D=
"noreferrer">http://eel.is/c++draft/intro.progress</a><br></div><div dir=3D=
"auto"><br></div><div dir=3D"auto">Quote:</div><div dir=3D"auto"><div dir=
=3D"auto" style=3D"background-image:inherit;background-size:inherit;backgro=
und-origin:inherit;background-clip:inherit;display:inline;font-family:&quot=
;times new roman&quot;;text-align:justify;background-position:inherit inher=
it;background-repeat:inherit inherit">The implementation may assume that an=
y thread will eventually do one of the following:<ul style=3D"list-style-ty=
pe:none;padding-left:9mm;margin-top:0px;margin-bottom:0px"><li style=3D"mar=
gin-top:3pt;margin-bottom:3pt"><div style=3D"background-image:inherit;backg=
round-size:inherit;background-origin:inherit;background-clip:inherit;backgr=
ound-position:inherit inherit;background-repeat:inherit inherit"><a href=3D=
"http://eel.is/c++draft/intro.progress#1.1" style=3D"text-decoration-line:n=
one;width:15mm;font-size:7pt;text-align:right" target=3D"_blank" rel=3D"nor=
eferrer">(1.1)</a></div>terminate,</li><li style=3D"margin-top:3pt;margin-b=
ottom:3pt"><div style=3D"background-image:inherit;background-size:inherit;b=
ackground-origin:inherit;background-clip:inherit;background-position:inheri=
t inherit;background-repeat:inherit inherit"><a href=3D"http://eel.is/c++dr=
aft/intro.progress#1.2" style=3D"text-decoration-line:none;width:15mm;font-=
size:7pt;text-align:right" target=3D"_blank" rel=3D"noreferrer">(1.2)</a></=
div>make a call to a library I/O function,</li><li style=3D"margin-top:3pt;=
margin-bottom:3pt"><div style=3D"background-image:inherit;background-size:i=
nherit;background-origin:inherit;background-clip:inherit;background-positio=
n:inherit inherit;background-repeat:inherit inherit"><a href=3D"http://eel.=
is/c++draft/intro.progress#1.3" style=3D"text-decoration-line:none;width:15=
mm;font-size:7pt;text-align:right" target=3D"_blank" rel=3D"noreferrer">(1.=
3)</a></div>perform an access through a volatile glvalue, or</li><li style=
=3D"margin-top:3pt;margin-bottom:3pt"><div style=3D"background-image:inheri=
t;background-size:inherit;background-origin:inherit;background-clip:inherit=
;background-position:inherit inherit;background-repeat:inherit inherit"><a =
href=3D"http://eel.is/c++draft/intro.progress#1.4" style=3D"text-decoration=
-line:none;width:15mm;font-size:7pt;text-align:right" target=3D"_blank" rel=
=3D"noreferrer">(1.4)</a></div>perform a synchronization operation or an at=
omic operation<a href=3D"http://eel.is/c++draft/intro.progress#1.sentence-1=
" style=3D"text-decoration-line:none" target=3D"_blank" rel=3D"noreferrer">=
.</a></li></ul></div><span style=3D"font-family:&quot;times new roman&quot;=
;font-size:16px;text-align:justify"></span><div dir=3D"auto" style=3D"backg=
round-image:inherit;background-size:inherit;background-origin:inherit;backg=
round-clip:inherit;margin-top:5pt;margin-bottom:5pt;font-size:11pt;font-fam=
ily:&quot;times new roman&quot;;text-align:justify;background-position:inhe=
rit inherit;background-repeat:inherit inherit"><div style=3D"background-ima=
ge:inherit;background-size:inherit;background-origin:inherit;background-cli=
p:inherit;margin-top:3pt;margin-bottom:3pt;background-position:inherit inhe=
rit;background-repeat:inherit inherit">[<i>Note=C2=A0<a href=3D"http://eel.=
is/c++draft/intro.progress#note-1" style=3D"text-decoration-line:none" targ=
et=3D"_blank" rel=3D"noreferrer">1</a></i>:=C2=A0<div style=3D"background-i=
mage:inherit;background-size:inherit;background-origin:inherit;background-c=
lip:inherit;display:inline;background-position:inherit inherit;background-r=
epeat:inherit inherit">This is intended to allow compiler transformations s=
uch as<span>=C2=A0</span><b>removal of empty loops, even when termination c=
annot be proven<a href=3D"http://eel.is/c++draft/intro.progress#1.sentence-=
2" style=3D"text-decoration-line:none" target=3D"_blank" rel=3D"noreferrer"=
>.</a></b></div><b>=C2=A0</b>=E2=80=94=C2=A0<i>end note</i>]</div></div></d=
iv></div></div></blockquote><div><br></div><div>Empty loop optimizations ha=
ve been around for a long time.=C2=A0 I suppose you may be trying to tell m=
e that there=E2=80=99s all kinds of places in all kinds of ways that your c=
ode may disappear or executed differently than you expect?</div><div><br></=
div><div>Gregg Wonderly</div></div><br></div></blockquote></div>

--0000000000009594be05c7d7a697--

--===============4917203794213877586==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KQ29uY3VycmVu
Y3ktaW50ZXJlc3QgbWFpbGluZyBsaXN0CkNvbmN1cnJlbmN5LWludGVyZXN0QGNzLm9zd2Vnby5l
ZHUKaHR0cDovL2NzLm9zd2Vnby5lZHUvbWFpbG1hbi9saXN0aW5mby9jb25jdXJyZW5jeS1pbnRl
cmVzdAo=

--===============4917203794213877586==--