Re:In the C++ bag of tricks: scoped locks
by 8_hours_ago on Friday February 07, 2014 @01:07PM
(#7197697)
A very important gotcha with this approach is that any variable named "i" will be reset to 0 inside of the lock, and modifying "i" inside of the lock can cause an infinite loop.
This can be mitigated by generating a unique variable name with the C preprocessor: http://stackoverflow.com/questions/1132751/how-can-i-generat...
That being said, it's much better to use a standard method of scoped locking instead of trying to reinvent the wheel.