Home > Web Front-end > JS Tutorial > Javascript parallel operation implementation code_javascript skills

Javascript parallel operation implementation code_javascript skills

WBOY
Release: 2016-05-16 18:16:01
Original
920 people have browsed it

Let me guess from my personal point of view, how parallel computing will support front-end javascript.

1 An unlikely evolution

Display thread support
If Supporting display threads in Javascript may be a disaster. Current browsers parse and execute Javascript in the browser's ui thread.
For example, you can run while(true) in Javascript, which The browser interface will stop responding. Or through my previous article (Compile Javascript engine to provide sleep function for JavaScript: http://www.cnblogs.com/ioriwellings/archive/2010/08/16/1800416.html) Understand the process of the UI interface being blocked.
In addition, if the display supports threads, it will also support the synchronization primitive function of data synchronization between threads. Then there will be such a problem:
Acquiring the lock in a function, and in The lock is released in another function, but what if another function goes wrong, or another function is referenced from another file, and it happens that the file is not loaded due to some reasons (network problems, encoding problems), then A deadlock will occur.
So according to some of the reasons above, it is not realistic to support display threads in JavaScript.

2 Possible evolution

Invisible The following code declares the parallel operation FOR loop:


#pragma omp parallel for
for (i = 0; i < N; i )
 a[i] = 2 * i;


This method can avoid all the troubles encountered previously. Parallel operations are hosted inside the Javascript engine, so the Javascript engine has more space to process and optimize these parallel operations, such as calling openMP and Intel TBB internally. Parallel function.
So I speculate that this approach will likely be adopted.


3 Handling parallel exceptions

Since Javascript code is implicitly hosted in Parallel thread processing, so you may not get the exception status of a thread immediately, but you will not know that there is an exception in some code until all threads finish running.

4 Debugger Evolution

will produce a Javascript debugger that supports thread awareness, can analyze the information in each thread, and can freeze/resume the running of a thread.
Of course, it is similar to firebug. Debuggers written in Javascript scripts will also be greatly improved, but I think it is more ideal that debuggers for local applications will become mainstream, such as: visual studio.


5 Conclusion

Parallel computing will affect the execution performance of front-end Javascript. Many front-end effects written in Javascript, the performance of Javascript games will be changed and improved. But will I see this change in javascript? ?
If you really can’t wait, you can still compile the existing js engine, add a parallel computing interface, and then publish your own browser for customers to download. The multi-core function can still be used.

But it must be compatible with the current JavaScript specifications, otherwise other browsers will not be able to recognize your code, so the original serial code needs to be analyzed within the js engine, and it must be accurate, and the code can be converted into parallel code for optimization .I think this task is still very difficult.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template