HTML5 provides the mechanism called “WebWorkers”. This feature is very nice and you can learn more about it here: http://www.html5rocks.com/en/tutorials/workers/basics/. There is also a new feature called “MessageChannel” which is meant to be used for the communication among the different origins (http://somedomain and https://somedomain:8080). I think this article is useful to learn more about it: http://www.webgranth.com/html5-web-messaging-fresh-tutorial-for-cross-document-messaging.
This post is going to create two WebWorkers and let them communicate with each other through a MessageChannel. Moreover, the WebWorkers implement the Producer-consumer-problem. The WebWorker #1 is the producer. It generates Fibonacci numbers and posts the result to the WebWorker #2. The WebWorker #2 receives the numbers and removes some of them. When it’s done with the work it posts the result back to the WebWorker #1. The WebWorker #1 fills some numbers again and posts them back to the WebWorker #2 and so on…
See it in action here: http://producer-consumer-webworker.herokuapp.com/index.html
Fork it on GitHub: https://github.com/jepetko/webworker