Dart是否会在多核环境中并行执行隔离? [英] Will Dart execute isolates in parallel in a multi-core environment?

查看:232
本文介绍了Dart是否会在多核环境中并行执行隔离?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dart中的隔离株会利用多核环境中的所有可用核并行运行,还是会在单个核上多路复用?

Will isolates in Dart run in parallel utilizing all available cores on a multiple core environment, or will it multiplex on a single core?

Google在Dart编程语言中将 isolates (单线程并发单元)描述为轻量级线程",该线程在主堆栈上运行而没有阻塞.

Google has described isolates (a single-threaded unit of concurrency) in the Dart programming language as a "light weight thread" that operates on the main stack, without blocking.

因此,在我看来,因为它只能在单核上进行多路复用,而不能在SMP,双核,多核或集群环境中在多个核上并行运行.

Thus, it seems to me as it will only be able to multiplex on a single core and not be able to run in parallel over multiple cores in a SMP, dualcore, multicore or clustered environment.

尽管如此,我找不到任何信息,因此我提出了一个谦虚的问题.

Though, I can't find any information on this, hence my humble question.

推荐答案

警告:以下代码已过期,不适用于Dart 1.0.

简短答案

也许.

Warning: the code below is out of date and does not work with Dart 1.0.

Short answer

Maybe.

dart:隔离库指南指出:"隔离物可能在单独的进程或线程中运行,具体取决于实现方式.对于Web应用程序,隔离物可以编译为Web Worker(如果有)."(我的重点)

The dart:isolate library guide states: "Isolates might run in a separate process or thread, depending on the implementation. For web applications, isolates can be compiled to Web workers, if they are available." (my emphasis)

运行此代码并观察您的CPU负载将告诉您您的实现是否执行此操作.

Running this code and observing your CPU load will tell you if your implementation does this or not.

#import('dart:isolate');
main() {
  for (var tmp = 0; tmp < 5; ++tmp) {
    SendPort sendPort = spawnFunction(runInIsolate);
    sendPort.call(tmp).then((reply) {
      print(reply);
    });
  }
}

runInIsolate() {
  port.receive((msg, SendPort reply) {
    var k = 0;
    var max = (5 - msg) * 100000000; 
    for (var i = 0; i < max; ++i) {
        i = ++i - 1;
        k = i;
    }
    reply.send("I received: $msg and calculated $k");
  });
}

独立的dartvm 利用所有可用的内核并行运行隔离. Dart 的浏览器实现可能会有所不同,具体取决于是否实现了Web Worker.

The standalone dartvm will run isolates in parallel, utilizing all available cores. Browser implementations of Dart will likely vary depending on whether Web Workers are implemented or not.

这篇关于Dart是否会在多核环境中并行执行隔离?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆