Thread-safe memory copy
Briefly

In C and C++, copying memory using functions like memcpy can become problematic when multiple threads access the same memory locations simultaneously. This scenario results in data races and undefined behavior, which is not handled by the language itself. The responsibility for ensuring thread safety falls entirely on programmers, especially within complex applications like JavaScript engines, where user-initiated bugs can cause issues. The existence of undefined behavior allows these languages to maintain consistent performance across various platforms, but it involves risks that developers must manage.
A common operation in software is the copy of a block of memory. In C/C++, we often call the function memcpy for this purpose.
What happens if, while you are copying the data, another thread is modifying either the source or the destination? The result is fundamentally unpredictable and almost surely a programming error.
In the case of JavaScript engines like Google v8 using C++, users can accidentally write code leading to data races, resulting in undefined behavior according to the C++ standard.
Undefined behavior does not guarantee an error; instead, it places an additional responsibility on the programmer to ensure safe code, without any warranty from the language.
Read at Lemire
[
|
]