[PATCH][WIP] libstdc++: Make certain exceptions transaction_safe.
Torvald Riegel
triegel@redhat.com
Sat Nov 14 19:45:00 GMT 2015
The attached patch makes some exceptions transaction-safe, as require by
the Transactional Memory TS. It has some rough edges, but I'm hoping I
can sort them out quickly using your feedback. It only supports
logic_error and exception/bad_exception, but the other exceptions that
the TM TS specifies as transaction-safe basically require the same
support (notably, runtime_error is the same as logic_error, and their
subclasses don't add anything).
There are two things that complicate such support. First, it seems
better to not rely on -fgnu-tm of libstdc++ code for now (or at least we
tried to avoid this so far). Therefore, the transactional clones in
this patch are all manually instrumented (ie, the functions are C
functions with names matching the mangled names of the respective C++
functions, and the _ZGTt prefix signaling that they are txnal clones).
Second, exceptions still use a COW string internally, which cannot be
made transaction-safe with just compiler support because of the
reference counting implementation inside of COW strings, which uses
atomics. One would need something custom for that nonetheless.
Thus, the patch adds txnal clones as required. They are new exported
symbols, but not visible to nontransactional code. The only changes to
headers is transaction_safe[_dynamic] annotations where required by the
TS, and a few friend declarations. The annotaitons are only enabled if
a user compiles with -fgnu-tm. IOW, the changes are pretty much
invisible when not using the TM TS.
The patch doesn't include tests yet, but tests like this one seem to run
successfully on x86_64:
template<typename T> void thrower4(const string& what)
{
try
{
// Creating a temporary inside of the txn ICEs.
T t(what);
atomic_commit
{
_ITM_hackOrTxnProp (pr_atomicCancel);
dontoptimize (t.what());
throw T (what);
}
}
catch (T ex)
{
if (what != ex.what()) abort ();
}
}
thrower4<logic_error> ("test");
I can't yet test the destructors because of issues on the compiler side.
There are also commented-out calls to _ITM_setAssociatedException in the
code, which exist to show how we plan to support transaction
cancellation through exceptions (which needs some more libitm support
and bugfixes on the compiler side).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: txn-safe-exceptions.patch
Type: text/x-patch
Size: 16051 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20151114/735f161c/attachment.bin>
More information about the Libstdc++
mailing list