Web Workers - 他们创建实际线程吗? [英] Web Workers - do they create actual threads?

查看:59
本文介绍了Web Workers - 他们创建实际线程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直认为网络工作者会创建单独的线程,但今天我遇到了w3c网站上的规范。以下是关于网络工作者的引用:

I have always thought that web workers create separate threads, but today I ran into the spec on w3c website. Below is a citation about web workers:


这允许类似线程的操作,消息传递作为
协调机制。

This allows for thread-like operation with message-passing as the coordination mechanism.

问题是 - 如果它是线程,而不是实际线程有什么优势(性能)明智的)使用这项技术?

The question is - if it is thread-like, not actual thread what is an advantage(performance wise) of using this technology?

任何帮助将不胜感激!

推荐答案

是的,网络工作者创建实际线程(或进程,规范是灵活的)。根据 Web Workers 规范,创建工作人员时,第一步是:

Yes, web workers create actual threads (or processes, the spec is flexible on this). According to the Web Workers specification, when a worker is created the first step is:



  1. 创建一个单独的并行执行环境(即一个单独的线程或进程或等效结构),然后运行其中的其余步骤就是在这种情况下。

  1. Create a separate parallel execution environment (i.e. a separate thread or process or equivalent construct), and run the rest of these steps in that context.

出于计时API的目的,这是创建工人的官方时刻。

For the purposes of timing APIs, this is the official moment of creation of the worker.

(W3C Web Workers规范第4.4节)

(W3C Web Workers specification section 4.4)

所以明确指出在Web Workers中运行的代码在实际线程或进程中运行。

So it is explicitly specified that code running in Web Workers run in actual threads or processes.

尽管可以实现没有线程的Workers(请注意等效构造语言)为了在不支持线程的系统上使用,所有浏览器实现都将Web Workers实现为线程。

Although it is possible to implement Workers without threads (note the "equivalent construct" language) for use on systems that don't support threads, all browser implementations implement Web Workers as threads.

这篇关于Web Workers - 他们创建实际线程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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