Quick questions about parallelism and some amber features

Holo The Sage Wolf holo3146 at gmail.com
Sun Apr 23 18:20:11 UTC 2023


I don’t see how you can have parallelism without having some horrible
potential bugs.
Imagine the following situation:

public static AtomicBoolean bl = new AtomicBoolean(true);public static
void sideEffect() { bl.set(false); return true; }
Integer i = 0;switch (i) {
    case Integer i when bl.get() -> ...
    case Integer i when sideEffect() -> ...
    ...
}

In this example we can have:

   - Enter case 1 with correct state
   - Enter case 2 with correct state
   - Enter case 1 with wrong state

Using move variables we can create a (albeit a bit pathological) example
with any number of cases that all can be entered with a wrong state (apart
from maybe the default branch).

Also, it can be dangerous when the when clause is expensive. Maybe it is
possible to calculate the non-when clause in parallel fashion, but I don’t
know if it worth the effort

On Sat, Apr 22, 2023 at 4:16 AM David Alayachew <davidalayachew at gmail.com>
wrote:

>
> Hello Steve,
>
> Thank you for your response!
>
> > It feels to me that Boolean short circuiting in
> > conditionals and statement ordering in switches would
> > both preclude parallel evaluation of conditions
>
> I'm actually expecting you to be correct here.
>
> The reason I originally asked this question is because I have been doing a
> lot of study into when and where parallelism starts to become useful when
> coding in Java. Long story short, it improves performance way earlier than
> I ever expected. And not only that, Java actually does a whole bunch of
> parallelism itself under the hood too. Compilation, class loading, etc. I
> thought I knew the threshold at which parallelism would start being useful,
> but apparently it's way earlier than I thought.
>
> > absent some infective constery to wave away side effects
>
> Google does not seem to be much help. What does this quote mean?
>
> > In any event - do you envisage any benefit from parallel
> > evaluation? On such scales would runtime cost not be
> > dominated by dispatch and synchronisation?
>
> Well at this point, I have no idea. I don't really know where the ceiling
> is anymore, so I am testing out (what I think is) a complete long shot,
> just to give myself an upper bound here. Worst case is they say no, which
> is what I am expecting.
>
> Thank you for your time!
> David Alayachew
>
>

-- 
Holo The Wise Wolf Of Yoitsu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20230423/cb926080/attachment-0001.htm>


More information about the amber-dev mailing list