Compiling C++ modules
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 6 lines · Denis Vlasenko
Quoted 1 line
Additionally, C++ guarantees that if an exception is thrown after
spin_lock()is called, then thespin_unlock()will also be called. That's an interesting mechanism by itself.Life gets even more interesting when you hit another exception inside destructor(s) being executed due to first one. Say,
spin_unlock()discovers that lock is already unlocked and does "throwBUG_double_unlock".
You're not allowed to throw exceptions from inside the stack unwinding caused by another exception, terminate() gets called in this case. In most cases this isn't too hard to avoid, you just have to ensure that exceptions don't get thrown out of destructors. Your example isn't very good, why would you throw an exception in that case? The caller isn't going to be able to do anything useful with it since it's because of a coding bug, some kind of assert or BUG() would be more logical.
Signature · 3 lines
Robert Hancock Saskatoon, SK, Canada To email, remove "nospam" from [email protected] Home Page: http://www.roberthancock.com/