<div dir="ltr">The assumption here is that what you are wrapping into such a call is often slow, otherwise there is no problem to talk about, and you just wouldn't wrap it in such a call.<div><br></div><div>The problem with exposing such a class is that it will bind the future development of the JVM, because if people start to optimize their code to it (even indirectly through a framework), and then in a later version of the JVM there would be an overall better way, then they can't easily add it, because everybody would be upset, if their code becomes worse after upgrading to Java Many (even if after small code/framework upgrade it would be considerably better). So, it is perfectly understandable that it is not the first choice they want to do.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Brian S O'Neill <<a href="mailto:bronee@gmail.com">bronee@gmail.com</a>> ezt írta (időpont: 2023. júl. 15., Szo, 0:32):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">How would a call like `NativeUtils.runBlocking(() -> mytask())` be <br>
implemented? By using a thread pool / message queue / FJ pool? In doing <br>
so, I've introduced a context switch. If the native method didn't <br>
actually block, then I just added a context switch for no good reason.<br>
<br>
Internally, the JDK uses a special Blocker class to handle this case. <br>
The nice thing is that it doesn't introduce an extra context switch or <br>
heap allocation.<br>
<br>
The whole point of this entire message thread is to ask for a simple <br>
feature in which native threads can indirectly utilize this special <br>
class (or whatever is best suited) and keep things simple. As virtual <br>
thread support evolves over time, I don't need to change my code.<br>
<br>
On 2023-07-14 03:14 PM, Attila Kelemen wrote:<br>
<br>
> <br>
> As for " Sometimes I can use virtual threads, and sometimes I need to <br>
> use a regular FJ pool": It wouldn't be like that, because only the <br>
> operation which is slow and pinning (and not compensated) should be just <br>
> written like this: `NativeUtils.runBlocking(() -> mytask())`, instead of <br>
> just writing `mytask()`. It would never be a choice between do I start a <br>
> VT or submit it to a thread pool? And presumably this is not the <br>
> majority of your code. And that is what you would gain, that you still <br>
> are mostly using VT, only those special pinning methods are not.<br>
> <br>
</blockquote></div>