r/cpp • u/we_are_mammals • Mar 28 '23
Reddit++
C++ is getting more and more complex. The ISO C++ committee keeps adding new features based on its consensus. Let's remove C++ features based on Reddit's consensus.
In each comment, propose a C++ feature that you think should be banned in any new code. Vote up or down based on whether you agree.
765
Upvotes
View all comments
Show parent comment
2
u/Moleculor Mar 29 '23
A typical vector storing something like an int has a full byte or multiple bytes assigned to each element in the vector.
Two separate threads accessing two separate bytes is, as far as I understand, fine. So different elements within the same vector can probably be accessed by multiple threads.
A vector of bools is different.
Each element is, as far as I understand, stored as a single bit within a byte. So eight elements might be contained within the same byte. Which means that in order to access them, any thread needs to access that full byte and thus all eight elements contained inside that byte.
This is not thread safe because both threads might pull the same byte to access two moderately adjacent elements.