Author: Remi Meier <remi.me...@gmail.com> Branch: nogil-unsafe-2 Changeset: r90761:e55ed339c048 Date: 2017-03-20 15:17 +0100 http://bitbucket.org/pypy/pypy/changeset/e55ed339c048/
Log: add test for locks in write-barrier slowpath diff --git a/rpython/memory/gc/incminimark.py b/rpython/memory/gc/incminimark.py --- a/rpython/memory/gc/incminimark.py +++ b/rpython/memory/gc/incminimark.py @@ -860,7 +860,6 @@ major collection, and finally reserve totalsize bytes. """ - # rthread.acquire_NOAUTO(self.wb_slowpath_lock, 1) rgil.enter_master_section() minor_collection_count = 0 @@ -948,7 +947,6 @@ self.set_nursery_free(self.get_nursery_top() - self.debug_tiny_nursery) # - # rthread.release_NOAUTO(self.wb_slowpath_lock) return result collect_and_reserve._dont_inline_ = True diff --git a/rpython/translator/c/test/test_nogil.py b/rpython/translator/c/test/test_nogil.py --- a/rpython/translator/c/test/test_nogil.py +++ b/rpython/translator/c/test/test_nogil.py @@ -96,3 +96,67 @@ 'counter=2', 'counter=1', 'all threads done'] + + + def test_array_wb_slowpath(self): + import time, gc + from rpython.rlib import rthread, rposix + + class X: + def __init__(self, i): + self.i = i + + class State: pass + state = State() + + def worker(): + rthread.gc_thread_start() + + arrays = [] + for _ in range(state.arrays): + arrays.append([None]) + + x = None + xi = 0 + for i in range(1000): + xi = i + for idx in range(state.arrays): + x = X(xi) + arrays[idx][0] = x + x = None + + gc.collect(0) + + for idx in range(state.arrays): + assert arrays[idx][0].i == xi + + state.lock.acquire(True) + state.counter -= 1 + state.lock.release() + rthread.gc_thread_die() + + def entry_point(argv): + os.write(1, "hello\n") + + TS = int(argv[1]) + ARRS = int(argv[2]) + state.lock = rthread.allocate_lock() + state.counter = TS + state.arrays = ARRS + + for tid in range(TS): + rthread.start_new_thread(worker, ()) + + while True: + time.sleep(0.1) + if state.counter == 0: + break + os.write(1, "all threads done\n") + return 0 + + # + THREADS, ARRAYS = 4, 1000 + t, cbuilder = self.compile(entry_point) + data = cbuilder.cmdexec("%s %s" % (THREADS, ARRAYS)) + assert data.splitlines() == ['hello', + 'all threads done'] _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit