Comment on In the C++ bag of tricks: scoped locksComments−8_hours_ago12yA 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.
Comments
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.