mardi 2 avril 2019

Can std::memory_order_acquire and memory_order_release be used separately?

cppreference said the std::memory_order_acquire will prevent read and write from reordering before it. So i can use std::memory_order_acquire just for preventing from reorder at runtime without corresponding std::memory_order_release. For example

std::atomic<uint32_t> g_counter{};//Counter for thread in Fun
std::atomic<void*> g_data{};
void Fun()
{
    g_counter.fetch_add(1, std::memory_order_acquire)//acquire operation prevent load operation reorder before it
    void *data = g_data.load(std::memory_order_acquier)//acquire operation prevent fetch_sub operation reorder before it
    g_counter.fetch_sub(1, std::memory_order_relexed)


Is that true?

Aucun commentaire:

Enregistrer un commentaire