I need a lock guard as bellow,if my code was used by multithread,the lock would work,but do nothing for singlethread.I used a bool param to enable this feature.
Is there an implemention in boost?more stable and more strong?
thank you
In my opinion, a runtime cost of conducting the check (which I would expect to be comparable to the cost of simply locking the mutex anyway), plus the dev/maintenance cost of having the more complex code, outweighs the cost of just always having the lock guard. Just always have the lock guard. Simple, fast, easy.
While I'm here, the C++ standard library has its own mutexes and lock guards. No need to use boost.