mercredi 27 décembre 2017

C++ - synchronization of threads

I have this problem

Foo * foo = new Foo();

void A(){
  foo->a();
}

void B(){
  foo->b();
}

void C(){
  foo->reloadAll();
}

Once I enter method C and start reloading foo, I dont want to call A or B. However, A or B can be called together. In that case, I dont want to lock any threads.

How to synchronize this? I can use features provided by C++14. Currently, I am using active waiting (while loo with sleep) on atomic variable, but that is not ideal.

Aucun commentaire:

Enregistrer un commentaire