Author: Remi Meier Branch: c7-refactor Changeset: r781:0fa13ec9be0d Date: 2014-02-19 11:28 +0100 http://bitbucket.org/pypy/stmgc/changeset/0fa13ec9be0d/
Log: more info in test_random output diff --git a/c7/test/test_random.py b/c7/test/test_random.py --- a/c7/test/test_random.py +++ b/c7/test/test_random.py @@ -19,17 +19,17 @@ return "lp%d" % _root_numbering _global_time = 0 -def contention_management(our_trs, other_trs, wait=False): +def contention_management(our_trs, other_trs, wait=False, objs_in_conflict=None): if other_trs.start_time < our_trs.start_time: pass else: - other_trs.must_abort = True + other_trs.set_must_abort(objs_in_conflict) - if not other_trs.must_abort: - our_trs.must_abort = True + if not other_trs.check_must_abort(): + our_trs.set_must_abort(objs_in_conflict) elif wait: # abort anyway: - our_trs.must_abort = True + our_trs.set_must_abort(objs_in_conflict) class TransactionState(object): @@ -38,9 +38,18 @@ self.read_set = set() self.write_set = set() self.values = {} - self.must_abort = False + self._must_abort = False self.start_time = start_time + self.objs_in_conflict = set() + def set_must_abort(self, objs_in_conflict=None): + if objs_in_conflict is not None: + self.objs_in_conflict |= objs_in_conflict + self._must_abort = True + + def check_must_abort(self): + return self._must_abort + def has_conflict_with(self, committed): return bool(self.read_set & committed.write_set) @@ -53,8 +62,9 @@ self.values.update(committed.values) if self.has_conflict_with(committed): - contention_management(self, committed) - return self.must_abort + contention_management(self, committed, + objs_in_conflict=self.read_set & committed.write_set) + return self.check_must_abort() def read_root(self, r): self.read_set.add(r) @@ -137,7 +147,7 @@ trs = self.transaction_state gtrs = self.global_state.committed_transaction_state self.global_state.check_for_write_read_conflicts(trs) - conflicts = trs.must_abort + conflicts = trs.check_must_abort() if not conflicts: # update global committed state w/o conflict assert not gtrs.update_from_committed(trs) @@ -146,7 +156,7 @@ return conflicts def abort_transaction(self): - assert self.transaction_state.must_abort + assert self.transaction_state.check_must_abort() self.roots_on_stack = self.roots_on_transaction_start del self.saved_roots[self.roots_on_stack:] self.transaction_state = None @@ -161,41 +171,48 @@ self.committed_transaction_state = TransactionState(0) def push_state_to_other_threads(self, tr_state): - assert not tr_state.must_abort + assert not tr_state.check_must_abort() for ts in self.thread_states: other_trs = ts.transaction_state if other_trs is None or other_trs is tr_state: continue other_trs.update_from_committed(tr_state, only_new=True) - if tr_state.must_abort: - self.ex.do('# conflict while pushing to other threads') + if tr_state.check_must_abort(): + self.ex.do('# conflict while pushing to other threads: %s' % + tr_state.objs_in_conflict) def check_for_write_write_conflicts(self, tr_state): - assert not tr_state.must_abort + assert not tr_state.check_must_abort() + for ts in self.thread_states: + other_trs = ts.transaction_state + if other_trs is None or other_trs is tr_state: + continue + + confl_set = other_trs.write_set & tr_state.write_set + if confl_set: + contention_management(tr_state, other_trs, True, + objs_in_conflict=confl_set) + + if tr_state.check_must_abort(): + self.ex.do('# write-write conflict: %s' % + tr_state.objs_in_conflict) + + def check_for_write_read_conflicts(self, tr_state): + assert not tr_state.check_must_abort() for ts in self.thread_states: other_trs = ts.transaction_state if other_trs is None or other_trs is tr_state: continue - if other_trs.write_set & tr_state.write_set: - contention_management(tr_state, other_trs, True) + confl_set = other_trs.read_set & tr_state.write_set + if confl_set: + contention_management(tr_state, other_trs, + objs_in_conflict=confl_set) - if tr_state.must_abort: - self.ex.do('# write-write conflict') - - def check_for_write_read_conflicts(self, tr_state): - assert not tr_state.must_abort - for ts in self.thread_states: - other_trs = ts.transaction_state - if other_trs is None or other_trs is tr_state: - continue - - if other_trs.read_set & tr_state.write_set: - contention_management(tr_state, other_trs) - - if tr_state.must_abort: - self.ex.do('# write-read conflict') + if tr_state.check_must_abort(): + self.ex.do('# write-read conflict: %s' % + tr_state.objs_in_conflict) # ========== STM OPERATIONS ========== @@ -248,7 +265,7 @@ trs.write_root(r, v) global_state.check_for_write_write_conflicts(trs) - if trs.must_abort: + if trs.check_must_abort(): thread_state.abort_transaction() ex.do("py.test.raises(Conflict, stm_set_char, %s, %s)" % (r, repr(chr(v)))) else: @@ -265,7 +282,7 @@ class OpSwitchThread(Operation): def do(self, ex, global_state, thread_state): trs = thread_state.transaction_state - conflicts = trs is not None and trs.must_abort + conflicts = trs is not None and trs.check_must_abort() # if conflicts: thread_state.abort_transaction() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit