morphologica
morphologica copied to clipboard
Consider thread safety of Vector (and vVector) classes
@niclar writes: "The underlying data structure of the Vector class is a std::array which if misaligned is subject to write tearing. (Further the atomic read/write assumption (guaranteed on x86/x64 for the fundamental datatypes, int, double..) should probably be asserted if the Vector was to be used in a multi threaded context)"
-One might argue that since you leave all threading up to the user it's their responsibility to ensure the above.
That's true, but I would at least like to have some comments in the code declaring exactly how thread safe/unsafe the class is. From this: https://docs.microsoft.com/en-us/cpp/standard-library/thread-safety-in-the-cpp-standard-library?view=msvc-170 I think that it's safe to read from a single Vector or vVector instance in different threads, but not to write to them from separate threads without ensuring that the writes occur at different times.
Useful info on std::atomic: https://stackoverflow.com/questions/31978324/what-exactly-is-stdatomic
These are as thread safe as std::array or std::vector. Closing.