Based on recent discussions among the C++ TM specification group, static constructors should be allowed in transactional (i.e., transaction_safe) code. GCC should have a wrapper assigment for __cxa_guard_acquire and __cxa_guard_release, and libitm should implement wrappers that guarantee atomicity of these constructors wrt the enclosing transaction.
If we find out that supporting and implementing isn't feasible in practice, GCC should provide a better error message (eg, "static constructors not allowed in transactional code" instead of complaining about the __cxa* functions), and we should move this test to the GCC tests. OK for branch?
commit 537788ae46aec7fcc45eee5ae56cfe3314a9ef11 Author: Torvald Riegel <trie...@redhat.com> Date: Wed Aug 3 13:31:46 2011 +0200 Test static constructors inside of transactional code. * testsuite/libitm.c++/static_ctor.C: New file. diff --git a/libitm/testsuite/libitm.c++/static_ctor.C b/libitm/testsuite/libitm.c++/static_ctor.C new file mode 100644 index 0000000..f618f68 --- /dev/null +++ b/libitm/testsuite/libitm.c++/static_ctor.C @@ -0,0 +1,38 @@ +// { dg-do run } +/* Tests static constructors inside of transactional code. */ + +#include <pthread.h> +#include <stdlib.h> + +int f(int x) __attribute__((noinline,transaction_safe)); +int f(int x) +{ + static int y = x; + return y*x; +} + +static void *thread (void *dummy __attribute__((unused))) +{ + int bar; + __transaction { bar = f(10); } + if (bar != 100) + abort(); + return 0; +} + +int main() +{ + int bar; + + // First, initialize y in another thread. + pthread_t pt; + pthread_create(&pt, NULL, thread, NULL); + pthread_join(pt, NULL); + + // Now y should already be initialized. + __transaction { bar = f(20); } + if (bar != 200) + abort(); + + return 0; +}