Author: Remi Meier
Branch: c7
Changeset: r704:679c5904557a
Date: 2014-02-05 13:48 +0100
http://bitbucket.org/pypy/stmgc/changeset/679c5904557a/
Log: fix missing read-barrier in duhton
diff --git a/c7/core.c b/c7/core.c
--- a/c7/core.c
+++ b/c7/core.c
@@ -124,6 +124,7 @@
uintptr_t lock_idx = (((uintptr_t)obj) >> 4) - READMARKER_START;
uint8_t lock_num = _STM_TL->thread_num + 1;
uint8_t prev_owner;
+ uint8_t retries = 0;
retry:
do {
prev_owner = __sync_val_compare_and_swap(&write_locks[lock_idx],
@@ -142,14 +143,18 @@
_stm_stop_safe_point(0);
goto retry;
}
- /* XXXXXX */
- //_stm_start_semi_safe_point();
- //usleep(1);
- //_stm_stop_semi_safe_point();
- // try again.... XXX
+
+
+ if (retries < 1) {
+ _stm_start_safe_point(0);
+ usleep(1);
+ _stm_stop_safe_point(0);
+ retries++;
+ goto retry;
+ }
+
stm_abort_transaction();
/* XXX: only abort if we are younger */
- spin_loop();
} while (1);
/* remove the write-barrier ONLY if we have the write-lock */
diff --git a/duhton/demo/synth.duh b/duhton/demo/synth.duh
new file mode 100644
--- /dev/null
+++ b/duhton/demo/synth.duh
@@ -0,0 +1,88 @@
+
+
+
+(defun clean_list (n)
+ (setq i n)
+ (setq res (list))
+ (while (> i 0)
+ (append res 0)
+ (setq i (- i 1))
+ )
+ res
+ )
+
+
+(setq _rand (container (list 133542157 362436069 521288629 88675123)))
+(defun xor128 ()
+ (setq lst (get _rand))
+ (setq x (get lst 0))
+ (setq y (get lst 1))
+ (setq z (get lst 2))
+ (setq w (get lst 3))
+
+ (setq t (^ x (<< x 11)))
+ (setq x y)
+ (setq y z)
+ (setq z w)
+
+ (setq w (^ w (^ (>> w 19) (^ t (>> t 8)))))
+ (set lst 0 x)
+ (set lst 1 y)
+ (set lst 2 z)
+ (set lst 3 w)
+ w
+ )
+
+
+(defun random_list (n max)
+ (setq i n)
+ (setq res (list))
+ (while (> i 0)
+ (append res (% (xor128) max))
+ (setq i (- i 1))
+ )
+ res
+ )
+
+
+
+
+(defun worker (shared private)
+ (setq i 1)
+ (while (< i 10000)
+ ;; every 200th modification is on 'shared'
+ (if (== (% i 200) 0)
+ (set shared (+ (get shared) 1))
+ (set private (+ (get private) 1))
+ )
+
+ (setq i (+ i 1))
+ )
+ )
+
+
+
+(setq N 800)
+(setq RAND_MAX 10)
+(setq CONFL_IF_BELOW 1)
+
+
+(setq shared (container 0))
+
+(setq rand-list (random_list N RAND_MAX))
+(setq i 0)
+(while (< i N)
+ (setq private (container 0))
+ (if (< (get rand-list i) CONFL_IF_BELOW)
+ ;; conflicting transaction
+ (transaction worker shared private)
+ ;; else non-conflicting
+ (transaction worker private private)
+ )
+
+ (setq i (+ i 1))
+ )
+
+(run-transactions)
+(print (quote shared) (get shared))
+
diff --git a/duhton/transaction.c b/duhton/transaction.c
--- a/duhton/transaction.c
+++ b/duhton/transaction.c
@@ -93,7 +93,7 @@
stm_start_inevitable_transaction();
root = du_pending_transactions;
- /* _du_read1(root); IMMUTABLE */
+ _du_read1(root); /* not immutable... */
if (root->cdr != Du_None) {
DuObject *cell = root->cdr;
@@ -135,8 +135,9 @@
stm_thread_local_obj = NULL;
while (__builtin_setjmp(here) == 1) { }
- stm_start_transaction(&here);
-
+ //stm_start_transaction(&here);
+ stm_start_inevitable_transaction();
+
/* _du_read1(pending); IMMUTABLE */
DuObject *result = _DuCons_CAR(pending);
DuObject *next = _DuCons_NEXT(pending);
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit