Re: Compiling C++ modules

From: Robert Hancock
Date: Thu Apr 27 2006 - 20:04:11 EST


Denis Vlasenko wrote:
Additionally, C++ guarantees that if an exception is thrown after spin_lock() is called, then the spin_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 "throw BUG_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.

--
Robert Hancock Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@xxxxxxxxxxxxx
Home Page: http://www.roberthancock.com/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/