The race condition

The garbage values which were there in the immediately previous two screenshots represent a classic race condition example. Do you remember the first image I showed you in the Introduction to SharedArrayBuffer section? Remember the SharedArrayBuffer linking to CPU 1 and CPU 2, which links to Worker 1 and Worker 2? Well, it turns out it's not completely correct.

Here's how the actual setup is in your machine:

The problem arises here. Race condition means that CPU 1 fetches the shared memory and sends it to Worker 1. Meanwhile, CPU 2 also fetches it, but doesn't know that CPU 1 is already working on it. So, by the time Worker ...

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.