| OLD | NEW |
| 1 All code in Dart runs in the context of an isolate. | 1 All code in Dart runs in the context of an isolate. |
| 2 Use additional isolates for concurrent programming | 2 Use additional isolates for concurrent programming |
| 3 and to run third-party code more securely. | 3 and to run third-party code more securely. |
| 4 | 4 |
| 5 ### Isolate concepts | 5 ### Isolate concepts |
| 6 | 6 |
| 7 Each isolate has its own heap, which means that all its values in memory, | 7 Each isolate has its own heap, which means that all its values in memory, |
| 8 including globals, are available only to that isolate. The only mechanism | 8 including globals, are available only to that isolate. The only mechanism |
| 9 available to communicate between isolates is to pass messages. | 9 available to communicate between isolates is to pass messages. |
| 10 Messages are sent through ports. | 10 Messages are sent through ports. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 #### Spawning isolates | 60 #### Spawning isolates |
| 61 | 61 |
| 62 Any top-level function or static method | 62 Any top-level function or static method |
| 63 ([not currently working](#isolates-static-method)) | 63 ([not currently working](#isolates-static-method)) |
| 64 is a valid entry point for an isolate. | 64 is a valid entry point for an isolate. |
| 65 The entry point should not expect arguments and should return void. | 65 The entry point should not expect arguments and should return void. |
| 66 It is illegal to use a function closure as an entry point to an isolate. | 66 It is illegal to use a function closure as an entry point to an isolate. |
| 67 Pass the entry point to | 67 Pass the entry point to |
| 68 [spawnFunction()](http://api.dartlang.org/dart_isolate.html#spawnFunction). | 68 [spawnFunction()](http://api.dartlang.org/dart_isolate.html#spawnFunction). |
| 69 | 69 |
| 70 <aside class="note" id="isolates-static-method" markdown="1"> | 70 <aside id="isolates-static-method"> |
| 71 <b>Note:</b> Both the dart2js compiler and the Dart VM | 71 <div class="alert alert-info"> |
| 72 ([bug #3011](http://code.google.com/p/dart/issues/detail?id=3011)) do not yet | 72 <strong>Tip:</strong> |
| 73 support static methods as isolate entry points. | 73 <b>Note:</b> Both the dart2js compiler and the Dart VM |
| 74 <a href="http://code.google.com/p/dart/issues/detail?id=3011">bug #3011</a> |
| 75 do not yet support static methods as isolate entry points. |
| 76 </div> |
| 74 </aside> | 77 </aside> |
| 75 | 78 |
| 76 {% highlight dart %} | 79 {% highlight dart %} |
| 77 #import('dart:isolate'); | 80 #import('dart:isolate'); |
| 78 | 81 |
| 79 runInIsolate() { | 82 runInIsolate() { |
| 80 print("hello from an isolate!"); | 83 print("hello from an isolate!"); |
| 81 } | 84 } |
| 82 | 85 |
| 83 main() { | 86 main() { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 228 |
| 226 In the above example, the child isolate runs to completion | 229 In the above example, the child isolate runs to completion |
| 227 because the main isolate keeps a ReceivePort open. | 230 because the main isolate keeps a ReceivePort open. |
| 228 The main isolate creates a ReceivePort to wait for | 231 The main isolate creates a ReceivePort to wait for |
| 229 a "shutdown" message. The term "shutdown" is arbitrary; the ReceivePort | 232 a "shutdown" message. The term "shutdown" is arbitrary; the ReceivePort |
| 230 simply needs to wait for some signal. | 233 simply needs to wait for some signal. |
| 231 | 234 |
| 232 Once the main isolate receives a "shutdown" message, it closes the | 235 Once the main isolate receives a "shutdown" message, it closes the |
| 233 ReceivePort. With the ReceivePort closed and nothing else to do, | 236 ReceivePort. With the ReceivePort closed and nothing else to do, |
| 234 the main isolate terminates, causing the app to exit. | 237 the main isolate terminates, causing the app to exit. |
| OLD | NEW |