Author: Armin Rigo <[email protected]>
Branch:
Changeset: r312:4d0b9fa7c7b8
Date: 2013-06-27 19:20 +0200
http://bitbucket.org/pypy/stmgc/changeset/4d0b9fa7c7b8/
Log: Finish transaction.c
diff --git a/duhton/test/test_transaction.py b/duhton/test/test_transaction.py
--- a/duhton/test/test_transaction.py
+++ b/duhton/test/test_transaction.py
@@ -13,15 +13,27 @@
(defun g (n)
(if (>= n 12)
(print n)
- (g (+ n 1))
- (g (+ n 2))))
- (transaction g 0)
+ (transaction g (+ n 1))
+ (transaction g (+ n 2))))
+ (g 0)
""")
pieces = got.splitlines()
assert len(pieces) == 377
assert pieces.count('12') == 233
assert pieces.count('13') == 144
+def test_multiple_starts_conflicts():
+ got = run("""
+ (setq c (list))
+ (defun g (n)
+ (if (>= n 12)
+ (append c n)
+ (transaction g (+ n 1))
+ (transaction g (+ n 2))))
+ (g 0)
+ """)
+ assert got == '' # how to print the final c ?? at least check no crash
+
def test_conflict_container():
for i in range(20):
res = run("""
diff --git a/duhton/transaction.c b/duhton/transaction.c
--- a/duhton/transaction.c
+++ b/duhton/transaction.c
@@ -2,7 +2,9 @@
#include <pthread.h>
#include <unistd.h>
+#ifndef NUM_THREADS
#define NUM_THREADS 4
+#endif
static DuConsObject du_pending_transactions = {
@@ -110,8 +112,21 @@
if (next != Du_None) {
/* we have more than one: add the others to the global list */
- assert(!"XXX");
- abort();
+ DuObject *tail = next;
+
+ while (1) {
+ _du_read1(tail);
+ DuObject *tailnext = ((DuConsObject *)tail)->cdr;
+ if (tailnext == Du_None)
+ break;
+ tail = tailnext;
+ }
+
+ DuConsObject * root = &du_pending_transactions;
+ _du_write1(tail);
+ _du_write1(root);
+ ((DuConsObject *)tail)->cdr = root->cdr;
+ root->cdr = next;
}
return result;
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit