Let's suppose we are working on a real-time performance-critical application, which is the reason we're so concerned about this interesting topic. Suppose I have two web workers running in the background, and I want to share some data from one worker to another. Web workers run independently on separate OS-level threads and have no idea about each other.
One way is to make use of postMessage
to transfer messages between web workers, as we saw in the last chapter. However, this is slow.
Another way is to transfer the object to another worker completely; however, if you remember, that makes the object which is transferred inaccessible from the worker which sent it.
The solution to this problem is SharedArrayBuffer
.