[pypy-commit] pypy nogil-unsafe-2: add another test

fijal pypy.commits at gmail.com
Tue Jul 11 08:41:26 EDT 2017


Author: fijal
Branch: nogil-unsafe-2
Changeset: r91855:7f09446cd7df
Date: 2017-07-11 14:40 +0200
http://bitbucket.org/pypy/pypy/changeset/7f09446cd7df/

Log:	add another test

diff --git a/rpython/rlib/rthread.py b/rpython/rlib/rthread.py
--- a/rpython/rlib/rthread.py
+++ b/rpython/rlib/rthread.py
@@ -159,7 +159,7 @@
     def __init__(self, ll_lock):
         self._lock = ll_lock
 
-    def acquire(self, flag):
+    def acquire(self, flag=True):
         if flag:
             c_thread_acquirelock(self._lock, 1)
             return True
diff --git a/rpython/translator/c/test/test_standalone.py b/rpython/translator/c/test/test_standalone.py
--- a/rpython/translator/c/test/test_standalone.py
+++ b/rpython/translator/c/test/test_standalone.py
@@ -1256,8 +1256,71 @@
         assert SUPPORT__THREAD
         runme(no__thread=False)
 
+    def test_thread_and_gc_medium(self):
+        import time, gc
+        from rpython.rlib import rthread, rposix
 
-    def test_thread_and_gc(self):
+        class State(object):
+            def _init_(self):
+                self._lock = rthread.allocate_lock()
+                self.counter = 0
+                self.l = []
+
+            def append(self, item):
+                self._lock.acquire()
+                self.l.append(item)
+                self._lock.release()
+
+            def get_counter(self):
+                self._lock.acquire()
+                r = self.counter
+                self.counter += 1
+                self._lock.release()
+                return r
+
+        state = State()
+
+        class Node(object):
+            def __init__(self, c):
+                self.c = c
+
+        def bootstrap():
+            rthread.gc_thread_start()
+            state.append(Node(state.get_counter()))
+            rthread.gc_thread_die()
+
+        def new_thread():
+            ident = rthread.start_new_thread(bootstrap, ())
+            return ident
+
+        def entry_point(argv):
+            # start 5 new threads
+            state._init_()
+            new_thread()
+            new_thread()
+            #
+            gc.collect()
+            #
+            new_thread()
+            new_thread()
+            new_thread()
+            time.sleep(0.5)
+            for item in state.l:
+                os.write(1, str(item.c) + "\n")
+            os.write(1, "ok\n")
+            return 0
+
+        def runme(no__thread):
+            t, cbuilder = self.compile(entry_point, no__thread=no__thread)
+            data = cbuilder.cmdexec('')
+            r = data.splitlines()
+            r.sort()
+            assert r == ['0', '1', '2', '3', '4', 'ok']
+
+        assert SUPPORT__THREAD
+        runme(no__thread=False)
+
+    def test_thread_and_gc_large(self):
         import time, gc
         from rpython.rlib import rthread, rposix
         from rpython.rtyper.lltypesystem import lltype


More information about the pypy-commit mailing list