简体   繁体   English

浏览器仍然是单线程吗?

[英]Are browsers still single-thread?

I listened to an old lecture from Crockford on Javascript (2006) and he was talking about the model 我听了Crockford关于Javascript(2006)的一次老演讲,他在谈论模型

Flow  -> Paint
  ^        | 
  |        v
Script <- Event

(a loop involving Flow, paint, event, script ...), saying "because all browsers are single threaded". (涉及Flow,paint,event,script ...的循环),说“因为所有浏览器都是单线程的”。

So, my question is, are they still single threaded? 所以,我的问题是,它们仍然是单线程的吗?

And for those who might know, are these video lectures still relevant in terms of what is taught? 对于那些可能知道的人来说,这些视频讲座在所教授的内容方面是否仍然有意义?

In terms of the JavaScript you get to run, yes. 就JavaScript而言,您可以运行。 This is normally not an issue because anything you intend to execute in JavaScript that might take more than a millisecond can be expressed as an "asynchronous" operation (for instance, AJAX requests, animation transitions, etc). 这通常不是问题,因为您打算在JavaScript中执行的所有可能花费一毫秒以上的时间都可以表示为“异步”操作(例如,AJAX请求,动画过渡等)。 That means all your code does is start the operation, and register possible callbacks for it to finish. 这意味着您的所有代码要做的就是开始操作,并注册可能的回调以使其完成。

There are very infrequent exceptions to that where it makes sense to have a "Web Worker", but I have never actually seen those put to use. 对于拥有“ Web Worker”有意义的情况,很少有例外,但是我从未真正看到过使用它们的情况。

Technically yes they are still all running single threads in the treatment of generating your page and actions on the front end. 从技术上讲,是的,它们仍然都在运行单线程,以处理在前端生成页面和操作的问题。 There are ways to make it seem like it isn't and run a javascript process independently like a pseudo multi thread using web workers introduced in html5. 有多种方法可以使它看起来像不是,并且可以像使用html5中引入的Web worker一样运行伪多线程那样独立运行javascript进程。 By pseudo I mean it works like most multi threaded processes it switches so fast between the clock interrupts it seems as if it's multi threaded. 伪我的意思是说,它的工作原理与大多数多线程进程一样,它在时钟中断之间切换得如此之快,似乎就像是多线程一样。 More information on web workers can be found at http://www.w3schools.com/html/html5_webworkers.asp as well as google of course. 有关网络工作者的更多信息, 请访问http://www.w3schools.com/html/html5_webworkers.asp以及Google。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM