Author: Remi Meier <remi.me...@inf.ethz.ch> Branch: Changeset: r261:0d81c9b1ec8e Date: 2014-05-28 09:18 +0200 http://bitbucket.org/pypy/benchmarks/changeset/0d81c9b1ec8e/
Log: some use of hint_commit_soon diff --git a/multithread/bottle/app.py b/multithread/bottle/app.py --- a/multithread/bottle/app.py +++ b/multithread/bottle/app.py @@ -1,4 +1,5 @@ -from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool +from common.abstract_threading import ( + atomic, Future, set_thread_pool, ThreadPool, hint_commit_soon) from BaseHTTPServer import HTTPServer import threading, time @@ -55,7 +56,12 @@ @bottle.route('/') def index(): - time.sleep(0.5) + with atomic: + i = 10000 + res = "" + while i: + i -= 1 + res += str(i) return "hi from " + threading.currentThread().getName() diff --git a/multithread/btree/btree.py b/multithread/btree/btree.py --- a/multithread/btree/btree.py +++ b/multithread/btree/btree.py @@ -1,6 +1,8 @@ # https://github.com/MartinThoma/algorithms/tree/master/datastructures -from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool +from common.abstract_threading import ( + atomic, Future, set_thread_pool, ThreadPool, + hint_commit_soon, print_abort_info) import time, threading import random @@ -203,6 +205,7 @@ ancestors.append((node, index)) node, index = ancestors.pop() node.insert(index, item, ancestors) + hint_commit_soon() return True def remove(self, item): @@ -211,6 +214,7 @@ if self._present(item, ancestors): node, index = ancestors.pop() node.remove(index, ancestors) + hint_commit_soon() # else: # raise ValueError("%r not in %s" % (item, self.__class__.__name__)) @@ -307,7 +311,8 @@ ###################################################################### ###################################################################### -OPS = [BTree.__contains__] * 98 + [BTree.insert, BTree.remove] +CONFLICTING = [BTree.insert, BTree.remove] +OPS = [BTree.__contains__] * 98 + CONFLICTING ITEM_RANGE = 10000 @@ -319,8 +324,12 @@ for _ in xrange(ops): op = r.choice(OPS) elem = r.randint(1, ITEM_RANGE) + # cflts = op in CONFLICTING + # if cflts: + # hint_commit_soon() with atomic: op(tree, elem) + #print_abort_info(0.00001) print "task ended" diff --git a/multithread/common/abstract_threading.py b/multithread/common/abstract_threading.py --- a/multithread/common/abstract_threading.py +++ b/multithread/common/abstract_threading.py @@ -3,13 +3,16 @@ import thread, atexit, sys, time try: - from atomic import atomic, getsegmentlimit, print_abort_info + from atomic import (atomic, getsegmentlimit, print_abort_info, + hint_commit_soon) except: atomic = RLock() def getsegmentlimit(): return 1 def print_abort_info(tm=0.0): pass + def hint_commit_soon(): + pass class TLQueue_concurrent(object): @@ -140,7 +143,9 @@ def _task(self, func, *args, **kwargs): with self._cond: try: + hint_commit_soon() self._result = func(*args, **kwargs) + hint_commit_soon() except Exception as e: self._exception = e finally: diff --git a/multithread/raytrace/raytrace.py b/multithread/raytrace/raytrace.py --- a/multithread/raytrace/raytrace.py +++ b/multithread/raytrace/raytrace.py @@ -2,7 +2,9 @@ # Date: 14.03.2013 from math import sqrt, pi -from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool +from common.abstract_threading import ( + atomic, Future, set_thread_pool, ThreadPool, + print_abort_info, hint_commit_soon) import time AMBIENT = 0.1 @@ -133,6 +135,7 @@ (Vector(x/50.0-5,y/50.0-5,0)-cameraPos).normal()) col = trace(ray, objs, lightSource, 10) line[y] = (col.x + col.y + col.z) / 3.0 + #print_abort_info(0.00001) return x @@ -142,7 +145,6 @@ - def run(ths=8, w=1024, h=1024): ths = int(ths) w = int(w) diff --git a/multithread/skiplist/skiplist.py b/multithread/skiplist/skiplist.py --- a/multithread/skiplist/skiplist.py +++ b/multithread/skiplist/skiplist.py @@ -1,6 +1,8 @@ # https://github.com/kunigami/blog-examples/tree/master/2012-09-23-skip-list -from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool +from common.abstract_threading import (atomic, Future, + set_thread_pool, ThreadPool, + print_abort_info, hint_commit_soon) import time, threading import random @@ -52,7 +54,7 @@ def insert(self, elem): node = SkipNode(self.randomHeight(), elem) - # conflicts with every find(): + # conflicts with everything else: self.maxHeight = max(self.maxHeight, len(node.next)) while len(self.head.next) < len(node.next): @@ -64,16 +66,19 @@ node.next[i] = update[i].next[i] update[i].next[i] = node self.len += 1 + hint_commit_soon() def remove(self, elem): update = self.updateList(elem) x = self.find(elem, update) if x != None: + # conflicts with everything else: for i in reversed(range(len(x.next))): update[i].next[i] = x.next[i] if self.head.next[i] == None: self.maxHeight -= 1 self.len -= 1 + hint_commit_soon() def printList(self): for i in range(len(self.head.next)-1, -1, -1): @@ -84,9 +89,9 @@ print '' - -OPS = [SkipList.find] * 98 + [SkipList.insert, SkipList.remove] -ITEM_RANGE = 10000 +CONFLICTING = [SkipList.insert, SkipList.remove] +OPS = [SkipList.find] * 98 + CONFLICTING +ITEM_RANGE = 1000000 def task(id, slist, ops): print "start task with %s ops" % ops @@ -97,9 +102,13 @@ for _ in xrange(ops): op = r.choice(OPS) elem = r.randint(1, ITEM_RANGE) + # if op in CONFLICTING: + # hint_commit_soon() with atomic: op(slist, elem) + #print_abort_info(0.0001) + print "task ended" _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit