Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么JavaScript是单线程? #34

Open
koala-coding opened this issue Dec 18, 2019 · 0 comments
Open

为什么JavaScript是单线程? #34

koala-coding opened this issue Dec 18, 2019 · 0 comments
Labels
javascript javascript相关知识

Comments

@koala-coding
Copy link
Owner

js最初设计是运行在浏览器中,单线程是为了防止DOM渲染冲突问题
比如有这样一个场景: 假设有2个线程, 当它们同时对同一个DON进行操作, 一个进行修改,而另一个进行删除, 此时就会产生冲突 所以为了避免出现这样的冲突, javascript从一诞生就是单线程.
但是呢单线程始终是一个痛点, 为了利用多核 CPU 的计算能力,HTML5 提出 Web Worker 标准,允许 JavaScript 脚本创建多个线程。但是子线程完全受主线程控制,且不得操作 DOM

@koala-coding koala-coding added the javascript javascript相关知识 label Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript javascript相关知识
Projects
None yet
Development

No branches or pull requests

1 participant