> I believe your question is whether V8 supports preemptive > rescheduling, i.e., without cooperation from the executing script?
Yes, whether it support preemptive scheduling or not, is an aspect of my question. To simplify, what I want to know is "Can we treat a v8 Isolate as a user-space thread, if we can, does v8 permit embedder implement user-space scheduler to support preemptive scheduling between different isolates?" > It doesn't. It's allowed to call isolate->RequestInterrupt() and then > call isolate->TerminateExecution() from the callback but not > isolate->Exit(). This is also what I want to ask, as we all know the given isolate will terminate the previous execution when invoking `isolate->TerminateExecution()` inside the callback of `isolate->RequestInterrupt()`. Will v8 isolate save and restore the execution context (not v8::Context) so that the execution context of the current isolate can be restored and we can resume it in the future, just like what os scheduler do (context switch). >From your answer, I guess that v8 no longer maintaining the execution context after "isolate->TerminateExecution" and cleanup the stack frame, so we can't continue the execution from where we stopped? 在2020年8月11日星期二 UTC+8 下午6:26:25<Ben Noordhuis> 写道: > On Tue, Aug 11, 2020 at 9:38 AM Ran Aizen <abbshr...@gmail.com> wrote: > > > > I saw the v8 description says: > > > > > Isolate represents an isolated instance of the V8 engine. V8 isolates > have completely separate states. Objects from one isolate must not be used > in other isolates. The embedder can create multiple isolates and use them > in parallel in multiple threads. An isolate can be entered by at most one > thread at any given time. The Locker/Unlocker API must be used to > synchronize. > > > > According to my understanding, it seems one isolate can be run in > multiple thread (not in same time), and multiple isolate can be managed in > one thread. > > > > Because I want to use Isolate as the VM for my program in multi-tenant > case, so I read some of the v8 API, I found that `v8::Isolate` has some > APIs like: > > > > - `Isolate::enter`, `Isolate::exit` > > - `Isolate::TerminateExecution` > > - `Isolate::CancelTerminateExecution` > > - `Isolate::RequestInterrupt` > > > > So, is it possible to "schedule" massive isolates among multiple threads > using v8 public APIs like above or does v8 support to achieve the > "schedule" ? > > > > The "schedule" here means maybe: > > > > 1. work stealing: let a thread run an isolate which was created and init > by other thread to balanced the isolate distribution. > > 2. round-robin: one thread created multiple isolate, when an special > event happend (maybe recv an os signal), one of the running isolate could > be paused the execution progress, save the execution context and switch > into other isolate, after other isolate finished, resume the previous > isolate's execution. > > I believe your question is whether V8 supports preemptive > rescheduling, i.e., without cooperation from the executing script? > > It doesn't. It's allowed to call isolate->RequestInterrupt() and then > call isolate->TerminateExecution() from the callback but not > isolate->Exit(). > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/74a970c3-df95-4660-bbbe-d63fe2f63dcen%40googlegroups.com.