Код: Выделить всё
struct Node {
int number;
std::atomic_bool latch;
void add() {
lock();
number++;
unlock();
}
void lock() {
bool unlatched = false;
while(!latch.compare_exchange_weak(unlatched, true, std::memory_order_acquire));
}
void unlock() {
latch.store(false , std::memory_order_release);
}
};
Результат, к сожалению, не 20 миллионов.
Что мне здесь не хватает?
Подробнее здесь: https://stackoverflow.com/questions/265 ... der-atomic
Мобильная версия