Hello
When using OTL on IBM AIX with the IBM xlC compiler version 11, we discovered that std::uncaught_exception()
can return true if an exception is thrown in another thread. This means that OTL queries can silently fail to execute sometimes when exceptions are thrown in other unrelated parts of the program.
We found some limited information on this problem with std::uncaught_exception()
and threads on the IBM DeveloperWorks website (including confirmation from IBM staff that this problem affects xlC on AIX but not on Linux; this refers to xlC version 9 but we have confirmed the problem also exists in version 11). See: https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014531233
We propose the following change:
// this becomes the default from version 4.0.162 and on. // the #define is not enabled for vc++ 6.0 in version 4.0.167 and higher. -#if !defined(OTL_UNCAUGHT_EXCEPTION_ON) && !(defined(_MSC_VER)&&(_MSC_VER==1200)) +// also not enabled on IBM xlC for AIX (where the std::uncaught_exception +// flag is shared by all threads) +#if !defined(OTL_UNCAUGHT_EXCEPTION_ON) && !(defined(_MSC_VER)&&(_MSC_VER==1200)) && !(defined(__xlC__)&&defined(_AIX)) #define OTL_UNCAUGHT_EXCEPTION_ON #endif
Thanks!
Thomas
There are other versions of xlC, like 10, 12, and there are different patch
levels of each version of the compiler. Have you done any research on
whether IBM has a fix for it, or at least what specific version + patch
level of the compiler which has the problem? You may want to file a PMR
with IBM. It's not a good idea to disable std::uncaught_exception() for all
versions of xlC by default, which may break more code than it fixes.
On Mon, Feb 17, 2014 at 5:07 AM, Thomas Munro tdmunro@users.sf.net wrote:
Related
Patches: #4
Ok, I can reproduce the problem with the following two compilers (this is the output from
-qversion
):The first one seems to be the current latest level/patch. I don't have access to anything older. I guess it must be changing in the forthcoming C++11 compiler, since C++11 explicitly specifies that
std::uncaught_exception()
refers to the current thread, but I don't see how we could anticipate which future version numbers will be multithreaded. Do you think there is any point in including a check that only disables the macro ifdefined(_AIX) && (__IBMCPP__<=1201)
? Wouldn't it make more sense to leave it disabled for all AIX/xLC platforms until we get a positive sighting of one that works?We haven't filed a PMR. I will ask about that.
FWIW here is the test program I used:
I'll add #define OTL_UNCAUGHT_EXCEPTION_OFF for you to be able to turn the
feature off. That makes more sense. Check for updates on the OTL Web site.
On Mon, Feb 17, 2014 at 9:09 AM, Thomas Munro tdmunro@users.sf.net wrote:
Related
Patches: #4
Thomas,
Was the problem in 32-bit or 64-bit mode?
Thanks,
Sergei
Sergei Kuchin wrote:
Related
Patches: #4
Both (just tested the above program with
-q32
and-q64
in xlC 12.1).Thanks for the info.
On Thu, Feb 20, 2014 at 5:54 AM, Thomas Munro tdmunro@users.sf.net wrote:
Related
Patches: #4
Thomas,
I checked with the latest patch level of xlC 10, your test program shows
the same problem. It looks that IBM either doesn't give a shit about
"small problems", or they've not been aware of the problem all along.
That's a big gaping hole in their C++ runtime! Thanks for the info.
Sergei
Thomas Munro wrote:
Related
Patches: #4
Yeah, it's really not great. At a guess, they may be conservative about preserving ABI compatibility between runtime library versions, and not want to change it.
We have
OTL_DESTRUCTORS_DO_NOT_THROW
defined, so it looks like there is no way that exceptions can be thrown out of destructors causingstd::terminate()
anyway. So what could go wrong if we disable thestd::uncaught_exception()
early returns, I mean, don't these two techniques both solve the same problem?FWIW, I noticed that Herb Sutter recommends not using
std::uncaught_exception()
in http://www.gotw.ca/gotw/047.htm .Robert,
RIIA idiom is not complete: it recommends closing resources when objects
go out of scope (a.k.a. destructors). Also, it is recommended in general
to use exceptions to communicate exceptional conditions / errors. When a
destructor throws, and the exception is not caught, the program aborts.
So, it not clear how to reconcile the contradiction between the
recommendations, and the implementation. Hence,
std::uncaught_exception() is needed, but not recommended. There is
another good example in C++ of such contradiction: const member
functions / methods in a class, and "mutable" data members to hide the
fact of object mutability in a const method. Besides the fluke in
std::uncaught_exception() in xlC, every other C++ compiler that OTL has
been used with doesn't seem to have that type of a problem (at least,
nobody else complained about that specific problem so far).
Here's a link to an article on the other side of the argument about
throwing destructors: http://www.kolpackov.net/projects/c++/eh/dtor-1.xhtml
Cheers,
Sergei
Thomas Munro wrote:
Related
Patches: #4