3 ms·
> But it will at least have overhead for larger objects. Given that there's essentially no way to do atomic operations on larger objects (than machine-level ty
by PaulDavisThe1st 6y ago
> But it will at least have overhead for larger objects.
Given that there's essentially no way to do atomic operations on larger objects (than machine-level types), all std::atomic<> for such types must involve a mutex, and are therefore guaranteed to have performance implications.
std::atomic<T> provides syntax that treats std::atomic<int> and std::atomic<MyHugeObject> in precisely the same way. This is useful, but entirely misleading if you care about performance.
- mehrdadn 6y agoYou're arguing for my point, not against it. (Though your basis for it isn't even true; HTM could avoid mutexes.)
- PaulDavisThe1st 6y agoHTM?
- mehrdadn 6y agoHardware transactional memory. TSX-NI in Intel's case.
- pkolaczk 6y agoThey don't have to involve a mutex but some kind of synchronisation. A sequential lock is another way of efficiently implementing that, without blocking the happy read path. Instead of locking the large object, it detects if a read was atomic and retries if it was not.
- PaulDavisThe1st 6y agoTechnically speaking, this is still not atomic, merely lock-free. Still very useful, but not semantically equivalent to the store or load of a 32 or 64 bit integer value (for example).
- pkolaczk 6y agoSemantically it is atomic, because if the seq lock is implemented as a separate abstraction, the caller never observes a partially written value (no tearing). Retrying a broken read is just an implementation detail.