Concurrent Programming / Synchronization Using Web-Based JavaScript

Are there any synchronization primitives like barriers, semaphores, locks, monitors ... available in JavaScript / web workers or is there some kind of library that allows me to use such things (I think of something like java. util.concurrent in Java)?

Do workers have obscure properties that distinguish them from Threads (for example, can they share memory with the main thread)? Is there a limit to how many workers can be created (for example, for security reasons or something else ...)? Do I need to take particular care?

+4
source share
3 answers

Web workers do not have a shared memory concept; all messages transmitted between streams are copied. With this in mind, you do not have barriers, semaphores, locks, or monitors, because you do not need them in the web worker model.

The concept of shared memory was proposed back in February 2011, but the status is now wontfix due to the complexity of the developer => https://lists.webkit.org/pipermail/webkit-unassigned/2011-February/287595.html

It also has nice ads about web workers. http://blogs.msdn.com/b/ie/archive/2011/07/01/web-workers-in-ie10-background-javascript-makes-web-apps-faster.aspx

Hope this helps

+3
source

In short: there are no synchronization primitives in javascript, but they also don't need it, since JavaScript is essentially single-threaded :). Workers can only access their own scale (without manipulating dom manipulations) and send messages to the main thread ui, where the usual js is located. I’m not sure about the maximum number of employees, but I’m sure that this is a limitation, you can try it in a browser :)

Hope this helps!

+2
source

Here you have a jQuery-based library made for this purpose: http://www.megiddo.ch/jcon-q-rency .

Of course, the model is actually not identical to java.util.concurrent, since we are not dealing with the same environment as described in other answers ...

+2
source

All Articles