• Welcome to DictionaryForMids Forum.
 

(for developers:) backgroundExecution for htmlApp with Web Workers

Started by Gert, 01. January 2011, 16:57:11

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gert

One may wonder why currently in the htmlApp there is no possibility to execute the translations in the background by a separate thread. Well, the reason is simple: there is no adequate support for threads in the web browser's Javascript.

Javascript only knows 'Web Workers'; while these Web Workers support parallel execution, the Web Workers are much different from threads: the key characteristic of threads is the possibility to access shared objects. For example Thread1 may access MyObject and Thread2 may access the same MyObject. Web Workers cannot do that ! Each of the Web Workers has a separate execution environment where you have to pipe in the input data (with 'postMessage') and the Web Worker pipes ot the output data (again with 'postMessage').

Web Workers are nice for cases where some input data is processed and some output data is returned. Web Workers are not adequate for cases where elaborated object structures are manipulated, that is really where true threads are needed.

[Note: sometimes the term 'thread' is used when talk is about Web Workers; whatever wording is used: Web Workers cannot share objects, which makes them a poor solution in many cases].

On the other hand, parallel execution in a web browser's Javascript is only supported by Web Workers. In the case of DictionaryForMIDs, it is possible to run cancelable translations with Web Workers in the background, but due to the Web Workers characteristics this may require a few weird changes in the Translation Layer. I am very reluctant to introduce any design disarrangement due to Web Workers. Hmmm, I really need to think about a few different options.

If I should be wrong on any of my points on threads and Web Workers above, please help to enlight me !

Regards,
Gert