Early Access Loom Builds
Dávid Karnok
akarnokd at gmail.com
Wed Jul 31 06:47:55 UTC 2019
Okay, I see.
My next question is about FiberScope then.
If I understand correctly, FiberScope.close blocks if run in a traditional
thread and suspends if run in a Fiber. Thus opening a scope with try() in
the main method will block the main thread (i.e., down to the OS level)
until the execution falls out of try() and close is called, right?
Now if I have code that runs on a single-threaded ExecutorService, a
FiberScope still appears to block the underlying OS thread until try()
finishes:
var exec = Executors.newSingleThreadExecutor();
try {
var f = exec.submit(() -> {
try (var scope = FiberScope.open()) {
System.out.println("In scope");
Thread.sleep(1000);
}
System.out.println("Out of scope");
return null;
});
var f2 = exec.submit(() -> {
System.out.println("Another task");
Thread.sleep(250);
System.out.println("Back");
return null;
});
f.get();
f2.get();
} finally {
exec.shutdown();
}
prints
In scope
Out of scope
Another task
Back
"Another task" doesn't run until the first task ends. In practice, I don't
think I can scope the entire application and rewrite forks to
schedule(Executor, Runnable), partly because Executor may not even be
available at that point.
Is there a way (or does it make sense) to make FiberScope.open detect that
it is running on an Executor thus it doesn't have to block but use it for
resumption?
Alan Bateman <Alan.Bateman at oracle.com> ezt írta (időpont: 2019. júl. 29.,
H, 16:00):
> On 29/07/2019 06:16, Dávid Karnok wrote:
> > Thanks. I was hoping for some details on Continuation and
> > ContinuationScope, but those are TBD. I'd like to ask a question
> > because of that.
> Continuations are used as a lower level construct in the current
> prototype. TBD if they will be exposed initially. In any case, the run
> method will throw IllegalStateException if continuation hasn't yielded.
>
> -Alan
>
--
Best regards,
David Karnok
More information about the loom-dev
mailing list