This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
There is no rule against the use of shared variables, yes, of course you have to be careful, but there are many algorithms that use variables that are read by one task and written by another, that work fine. Surely you are not claiming that these algorithms are never allowed in C.
Of course not. It's up to the user to know what he's doing and there's the volatile keyword to avoid incorrect optimizations.
What I said was only meant for the mentioned situation of a std::vector, which needs to be in a coherent state in order to be read correctly. When a thread manipulates a vector, it might be in an incoherent state for a short time, during which it would be dangerous for another thread to read this same vector.
That was to point out that it's not up to the compiler to ensure thread-safety. The optimizer may assume there's only one thread, unless told otherwise, so it's perfectly valid to move the call to size() out of the loop.
Attachment:
signature.asc
Description: OpenPGP digital signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |