Questions and answers to JavaScript threads

Source: Internet
Author: User

Requirements:

JavaScript is single-threaded and has a task queue. For example, use Settimeou (func,secs) to add Func to the task queue after secs milliseconds. However, after the settimeout is followed by a dead loop, the dead loop causes the task to be blocked, which means that Func cannot run. I would like to ask: When the dead loop is running, secs milliseconds in the past, is the Func added to the task queue? Suppose to join, but JS is single-threaded, not joined in this thread, where is it added? The answer to the great God, a lot of things to find music, and JavaScript high-level programming in the same way.
For:

The reason is that JS is single thread. But the browser is multi-threaded. Even the multi-process. So. The same tab, there is only one interpreter. There may be more than one iframe ...

The addition of maintenance is a matter of other thread Cheng Gan, and running is a single-threaded interpreter doing things. Just like Java, there is a reflection mechanism, window is a host host object. That is, he uses C language to achieve. Not within JS's interpreter thread control, just to interact. So... You are clear, logically JS is a single thread, but there are actually very many other threads in the auxiliary interpreter. The implementation details only ensure that the logical integrity of the single thread can be


Some understandings about the handle handler:

Handle.

Handler, in fact, the word translation is quite graphic, although not very well understood. You can understand the remote control of the TV, the remote control in the hand. It's the equivalent of getting a TV object and trying to get the TV to do it. Then operate the "TV object". Persistence, which is generally referred to as a database, is not called persistent in memory.

The reboot is also coming. That's persistence.



Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Questions and answers to JavaScript threads

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.