As mentioned in the comments, the code seems to be "thread safe", however it may suffer from "cache hijacking".
First let me explain what it is and why it can happen in your code:
What is caching:
"-" - , . : . , . - 64 .
, , , , , . , , .
(. wiki ), , )
(. : Dr.Dobb article )
:
, calloc malloc, . (. man 3 calloc, FreeBSD).
++ new .
, , calloc malloc, , , mystruct, -.
"":
, (. wiki ).
, (mystruct), :
malloc calloc -.
posix: posix_memalign, <stdlib.h> (. opengroup posix_memalign)
++ 11 std::aligned_storage (. )
std::aligned_storage type, , .
, - , N :
struct mystruct { ... };
const std::size_t cache_line_size = 64;
typename std::aligned_storage<sizeof(mystruct), cache_line_size>::type storage[N];
, N- mystruct s, mystruct . IMO, , calloc mystruct.
. , - - .