Skip to content

Comment on In the C++ bag of tricks: scoped locks

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.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.