JavaScript 和线程 [英] JavaScript and Threads

查看:12
本文介绍了JavaScript 和线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在 JavaScript 中实现多线程?

Is there some way to do multi-threading in JavaScript?

推荐答案

参见 http://caniuse.com/#search=worker 获取最新的支持信息.

See http://caniuse.com/#search=worker for the most up-to-date support info.

以下是大约 2009 年的支持状态.

The following was the state of support circa 2009.

你想用谷歌搜索的词是JavaScript Worker Threads

除了 Gears 之外,目前没有任何可用的东西,但有很多关于如何实现它的讨论所以我想看这个问题,因为答案无疑会在未来改变.

Apart from from Gears there's nothing available right now, but there's plenty of talk about how to implement this so I guess watch this question as the answer will no doubt change in future.

以下是 Gears 的相关文档:WorkerPool API

Here's the relevant documentation for Gears: WorkerPool API

WHATWG 有一份针对工作线程的建议草案:Web Workers

WHATWG has a Draft Recommendation for worker threads: Web Workers

还有 Mozilla 的 DOM 工作线程

And there's also Mozilla’s DOM Worker Threads

更新: 2009 年 6 月,浏览器支持 JavaScript 线程的当前状态

Update: June 2009, current state of browser support for JavaScript threads

Firefox 3.5 有网络工作者.网络工作者的一些演示,如果你想看到他们的行动:

Firefox 3.5 has web workers. Some demos of web workers, if you want to see them in action:

  • Simulated Annealing ("Try it" link)
  • Space Invaders (link at end of post)
  • MoonBat JavaScript Benchmark (first link)

Gears 插件也可以安装在 Firefox 中.

The Gears plugin can also be installed in Firefox.

Safari 4WebKit nightlies 有工作线程:

Chrome 内置了 Gears,因此它可以执行线程,尽管它需要用户的确认提示(并且它对网络工作者使用不同的 API,尽管它可以在任何浏览器中使用安装了 Gears 插件):

Chrome has Gears baked in, so it can do threads, although it requires a confirmation prompt from the user (and it uses a different API to web workers, although it will work in any browser with the Gears plugin installed):

  • Google Gears WorkerPool 演示(不是一个很好的例子因为它运行速度太快而无法在 Chrome 和 Firefox 中进行测试,尽管 IE 运行它的速度足够慢,以至于可以看到它阻止交互)
  • Google Gears WorkerPool Demo (not a good example as it runs too fast to test in Chrome and Firefox, although IE runs it slow enough to see it blocking interaction)

IE8IE9 只能在安装了 Gears 插件的情况下执行线程

IE8 and IE9 can only do threads with the Gears plugin installed

这篇关于JavaScript 和线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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