Difference between DART Isolate and Thread (Java,C#)

雨燕双飞 提交于 2019-12-23 12:33:31

问题


For me The DART Isolate looks like a Thread (Java/C#) with a different terminology. In which aspect Isolate differs from a Thread?


回答1:


Threads use shared memory, isolates don't.

For example, the following pseudocode in Java/C#

class MyClass {
  static int count = 0;
}

// Thread 1: 
MyClass.count++;
print(MyClass.count); // 1;

// Thread 2:
MyClass.count++;
print(MyClass.count); // 2;

This also runs the risk of the shared memory being modified simultaneously by both threads.

Whereas in Dart,

class MyClass {
  static int count = 0;
}

// Isolate 1: 
MyClass.count++;
print(MyClass.count); // 1;

// Isolate 2:
MyClass.count++;
print(MyClass.count); // 1;

Isolates are isolated from each other. The only way to communicate between them is to pass messages. One isolate can listen for callbacks from the other.

Check out the docs here including the "isolate concepts" section.



来源:https://stackoverflow.com/questions/14957253/difference-between-dart-isolate-and-thread-java-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!