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] | |
So since one thread is reading (size() is a const method), and another may be writing (perhaps adding new elements), it's fine for such implementations.
Only if you can ensure both operation to not happen at the same time. If you call size() while another thread is just resizing the vector, you might get wrong results.
The compiler can't optimize away a function call if it doesn't know if the return value (or side effects) will be the same, right?
Correct. But for telling whether it may optimize away the call, the optimizer will assume there's no other thread manipulating the same vector. (If that wouldn't be, it would hardly be possible to optimize anything.) It's up to you to make sure this assumption holds true in every situation.
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] |