* [trans-mem] Test static constructors inside of transactional code
@ 2011-08-03 11:57 Torvald Riegel
2011-08-04 15:56 ` Richard Henderson
0 siblings, 1 reply; 2+ messages in thread
From: Torvald Riegel @ 2011-08-03 11:57 UTC (permalink / raw)
To: GCC Patches; +Cc: Aldy Hernandez, Richard Henderson
[-- Attachment #1: Type: text/plain, Size: 647 bytes --]
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?
[-- Attachment #2: patch7 --]
[-- Type: text/plain, Size: 1167 bytes --]
commit 537788ae46aec7fcc45eee5ae56cfe3314a9ef11
Author: Torvald Riegel <triegel@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;
+}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [trans-mem] Test static constructors inside of transactional code
2011-08-03 11:57 [trans-mem] Test static constructors inside of transactional code Torvald Riegel
@ 2011-08-04 15:56 ` Richard Henderson
0 siblings, 0 replies; 2+ messages in thread
From: Richard Henderson @ 2011-08-04 15:56 UTC (permalink / raw)
To: Torvald Riegel; +Cc: GCC Patches, Aldy Hernandez
On 08/03/2011 04:57 AM, Torvald Riegel wrote:
> Test static constructors inside of transactional code.
>
> * testsuite/libitm.c++/static_ctor.C: New file.
Ok.
> +static void *thread (void *dummy __attribute__((unused)))
This is C++. Unnamed parameters work.
r~
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-04 15:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-03 11:57 [trans-mem] Test static constructors inside of transactional code Torvald Riegel
2011-08-04 15:56 ` Richard Henderson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).