lundi 4 décembre 2017

condition_variable, mutex and flag in one struct

Is to ok to combine all three variables into one struct?

struct lock_struct
{
    std::mutex mutex;
    std::conditional_variable cv;
    bool flag;
};

Are there any hidden synchronization problems with this approach? I do not intend to modify struct itself, only it's fields.

By the way, should I use bool or std::atomic<bool> when dealing with std::condition_variable's flag?

Aucun commentaire:

Enregistrer un commentaire