Closed rockingdice closed 5 years ago
Isolates are either spawned using spawn
or spawnUri
. The spawnUri
function creates a completely new isolate running a different Dart script/program. There is no guarantee that a class existing in the spawner isolate also exists in the spawnee isolate, so sending of objects between such isolates is restricted to simple list/map structures.
When you use spawn
, you create a copy of the current isolate. It has all the same classes available, and many more objects can be sent between two such two isolates.
You can see spawn
as creating a new isolate in the same "family" of isolates as the spawning isolate. Each call to spawn
in a family will extend the family. Any call to spawnUri
will create a new family, which can the create more isolates using spawn
.
So, the initiial isolate does not have to be the root
isolate, it's just the first isolate of an isolate spawn-family. It's not special inside that family either, and it can terminate while other isolates in the same family keep running.
The Dart isolate communication is not concurrency based, each isolate runs single-threaded, and communication is only depending on the way the isolate was spawned. Running on multiple cores has no relation to this.
So, decide up-front how you are going to structure your isolate families. If the communicating isolates belong to different families, limit the data to simple types and list/maps of those.
@lrhn I think I'm quite clear now, thank you!
I see the comments in the package:
Does the initial isolate have to be the root isolate? If using custom objects instead of base values, will it limit the use for multi cores environment? If I want to take the advantage of multi-cores, any tips on better to do / not to do when using the registry?