dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.06k stars 1.55k forks source link

Using Isolate.terminateCapability for resuming the isolate #28333

Open alsemenov opened 7 years ago

alsemenov commented 7 years ago

The description for method Isolate.resume() reads:

void resume( Capability resumeCapability ) ... The capability must be one returned by a call to pause on this isolate, otherwise the resume call does nothing.

Description for method Isolate.pause() reads:

Capability pause([ Capability resumeCapability ]) ... If resumeCapability is provided, it is used to identity the pause, and must be used again to end the pause using resume. Otherwise a new resume capability is created and returned. ... Returns the capability that must be used to end the pause.

So it is possible to use Capability instance, supplied by programmer, for pause and resume. There are two special values null and Isolate.terminateCapability among others. The null case is covered by the specification. However the Isolate.terminateCapability case is not clear. Is this value considered as invalid? Should it be ignored or an error should be raised?

There is a similar case in Isolate constructor. It takes pause capability and terminate capability as arguments. Is it ok, if the same instance will be supplied for both?

lrhn commented 3 years ago

There is nothing inherently special about the terminate capability. A capability is just an unforgeable, send-port sendable token. You can use it for pausing, and all it means is that you must send the same capability again when resuming.