01 Race condition
Two helpers, one number. With and without a "key".
What is this?
Two helpers count to a big number. Each helper says
"+1" many, many times. The total should be exact.
Without a lock: both helpers sometimes read the same number, add 1, and save it. The other helper's "+1" is lost. The total is too small.
With a mutex (a "key"): only one helper at a time can change the number. The total is correct.
Show code real · web workers
Atomics.wait / notify are the JS equivalent
of Linux futex(2) — the same syscall pthread_mutex_t
uses inside.