mercredi 23 septembre 2020

C++ std::atomic for user defined data types

I am unable to understand and write up a code related to below Atomic Library functionality for user defined data type:

std::atomic::compare_exchange_weak, std::atomic::compare_exchange_strong

bool compare_exchange_weak( T& expected, T desired,
                            std::memory_order success,
                            std::memory_order failure );

bool compare_exchange_strong( T& expected, T desired,
                              std::memory_order success,
                              std::memory_order failure );

So if I have below trivial class how can I use compare_exchange_weak / compare_exchange_strong Atomic library methods on that trivial class?

class A
{
public:
    void Show()
    {
        std::cout << "Called\n";
    }
};

I am unsure what expected / desired values we should set in the method for user defined datatype - class A for example?

Aucun commentaire:

Enregistrer un commentaire