What about: #define LOCKED(lk) for(int i=lk_lock(lk); i == 0; lk_unlock(lk), i++) Probably better to test for 0 exactly, in case it fails. You don't want it to unlock twice just because it returns -1.
This is so wrong on so many levels.
In the C++ bag of tricks: scoped locks
51–56 of 56 posts
Re: In the C++ bag of tricks: scoped locks
#52Earlier quoted context omitted.
Which is mostly due to lack of education. If you don't ever spent time learning, but just coding, you don't know better. And sometimes it's all too easy to get thrapped into it due to deadlines and whatnot. A former collegue of mine, unfortunately, was the best example: programmed for like 15 years years and still wrote like it was all 'C with classes' (not that there ever was such a thing). You know, writing declara…
There was a C with Classes. http://www.stroustrup.com/bs_faq.html#invention
Re: In the C++ bag of tricks: scoped locks
#53Earlier quoted context omitted.
Which is mostly due to lack of education. If you don't ever spent time learning, but just coding, you don't know better. And sometimes it's all too easy to get thrapped into it due to deadlines and whatnot. A former collegue of mine, unfortunately, was the best example: programmed for like 15 years years and still wrote like it was all 'C with classes' (not that there ever was such a thing). You know, writing declara…
C with classes is what the google c++ style guide mandates: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... No exceptions, no boost, no lambda, no rtti, streams only for logging, avoid operator overloading, etc.
Re: In the C++ bag of tricks: scoped locks
#54Earlier quoted context omitted.
C with classes is what the google c++ style guide mandates: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... No exceptions, no boost, no lambda, no rtti, streams only for logging, avoid operator overloading, etc.
The Google C++ style guide has its quirks, but describing it as "C with classes" is flat out wrong. > no boost Not true, select parts of Boost are available. > no lambda The C++11 features are being rolled in gradually. Lambda expressions are now permitted. > no rtti The guide says "avoid RTTI" and urges the developer to come up with a different design. This is very much in line with C++ best practice overall. There'…
Do not use lambda expressions, or the related std::function or std::bind utilities.
Re: In the C++ bag of tricks: scoped locks
#55Re: In the C++ bag of tricks: scoped locks
#56Earlier quoted context omitted.
The Google C++ style guide has its quirks, but describing it as "C with classes" is flat out wrong. > no boost Not true, select parts of Boost are available. > no lambda The C++11 features are being rolled in gradually. Lambda expressions are now permitted. > no rtti The guide says "avoid RTTI" and urges the developer to come up with a different design. This is very much in line with C++ best practice overall. There'…
Version 3.274 says: Do not use lambda expressions, or the related std::function or std::bind utilities.