lundi 25 mai 2015

Is c++11 enum class thred safe?

I wonder what happens if I don't lock an enum variable in the following writer-reader situation:

enum class Foo {One,Two,Three};
Foo foo = Foo::One;

// Thread A:
wait_for_something();
// no mutex lock
foo= Foo::Two;

// Thread B:
while(foo==Foo::One){
// no mutex lock
do_something();
}

I can think of sequences that in the middle of do_something, foo changes. This is not really important, I would like to know if there is any other issues with this lockless code?

Aucun commentaire:

Enregistrer un commentaire