dimanche 24 juillet 2016

Synchronization of if blocks, C++

The project I'm working on uses a custom implementation of critical sections. The way I create a critical section is as follows: { CriticalSectionLock lock(m_criticalsection); ...//Stuff inside the critical section } When the CriticalSectionLock goes out of scope, the critical section ends. My problem is that I want to put the increment operation below inside a critical section (I can't use an atomic_int): if (0 == g_envCount++) {... I'd like to do something like the following: {CriticalSectionLock lock(m_criticalsection); if (0 == g_envCount++) } { But I think even if that works it's very confusing for the reader. Can someone suggest a better/cleaner way to do this?

Aucun commentaire:

Enregistrer un commentaire