3 ms·
If you use a two-word representation, you can't atomically set a value. At least on 32-bit x86 this isn't true. CMPXCHG8B can atomically write 64 bits of data
by pmjordan 16y ago
If you use a two-word representation, you can't atomically set a value.
At least on 32-bit x86 this isn't true. CMPXCHG8B can atomically write 64 bits of data and has been supported by CPUs for decades. The x86-64 equivalent, CMPXCHG16B, for atomic 128-bit writes is more problematic, as early Athlon64/Opteron CPUs did not support it. But even on 64-bit systems, a 64-bit encoding should be good enough. Technically, the address space can comprise 48 bits, but even if you steal a couple more than 16 for the NaN coding you should have more than enough for a few decades.
PowerPC, ARM, etc. have different atomicity guarantees though, which make this sort of thing more problematic. However, as far as I know, even Web Worker threads don't share JS context state with the main thread, so this is probably a non-issue.
I don't really see the practical benefit.
Probably to avoid cache misses.