Loading topic
ArrayBuffer and typed arrays such as Int32Array, and how to start a Web Worker and exchange messages with postMessage.2 min readSharedArrayBuffer and posted it to a worker. In a browser, that code throws a ReferenceError or fails to share memory unless the page is cross-origin isolated. This chapter explains why the requirement ex2 min readInt32Array work over an ordinary ArrayBuffer, and that you have created a SharedArrayBuffer as shown in the previous chapter.2 min readnew Worker(...), can read CommonJS require syntax, and have read the earlier chapters on creating a SharedArrayBuffer and wrapping it in typed arrays.2 min readSharedArrayBuffer, wrap it in an Int32Array, and pass it to a Node.js worker thread. It explains what goes wrong when several threads touch the same memory with ordinary JavaScript reads and writes.2 min readInt32Array, how to share a SharedArrayBuffer between threads, and why plain counter[0]++ loses updates when two threads run it at once. In this chapter you replace those plain accesses with operations from the Atomics object.2 min readInt32Array over a SharedArrayBuffer between worker threads, and that you have used Atomics.load, Atomics.store, and Atomics.add. Those built-in read-modify-write operations cover addition, subtraction, and bitwise logic. Some updates need other2 min readSharedArrayBuffer between threads, how to read and write it through an Int32Array, and how Atomics.load and Atomics.store work.2 min readAtomics.wait and Atomics.notify work from the previous chapter. It also assumes you are comfortable with Promises and the event loop.2 min readAtomics.compareExchange, Atomics.wait, and Atomics.notify from the previous chapters. You should also be able to start Node.js worker threads.2 min readSharedArrayBuffer between threads and how Atomics.store, Atomics.load, Atomics.wait, and Atomics.notify work. Here the question changes. Earlier chapters asked whether a single update is safe. This one asks when one thread's writes become visibl2 min readAtomics.load, Atomics.store, Atomics.wait, and Atomics.notify, and that you know how a sequentially consistent store publishes earlier writes to a thread that later loads it. It uses Node.js worker_threads so you can run the example without setting up 2 min readload, store, add, compareExchange) and the typed array views from earlier chapters: Int8Array, Int16Array, Int32Array, and BigInt64Array.2 min readSharedArrayBuffer, put typed array views on it, and send it to a worker. It also assumes you know the basic Atomics operations from earlier chapters.2 min readSharedArrayBuffer, cross-origin isolation, Atomics, and the mutex and ring buffer patterns. Here you will weigh the cost of those tools against plain postMessage.2 min read