Esempio n. 1
0
 def test_one_thread(self, skew=+1):
     from rpython.rlib.debug import debug_print
     if self.bigtest:
         N = 100000
         skew *= 25000
     else:
         N = 100
         skew *= 25
     space = FakeSpace()
     class State:
         pass
     state = State()
     def runme(main=False):
         j = 0
         for i in range(N + [-skew, skew][main]):
             state.datalen1 += 1   # try to crash if the GIL is not
             state.datalen2 += 1   # correctly acquired
             state.data.append((thread.get_ident(), i))
             state.datalen3 += 1
             state.datalen4 += 1
             assert state.datalen1 == len(state.data)
             assert state.datalen2 == len(state.data)
             assert state.datalen3 == len(state.data)
             assert state.datalen4 == len(state.data)
             debug_print(main, i, state.datalen4)
             gil.do_yield_thread()
             assert i == j
             j += 1
     def bootstrap():
         try:
             runme()
         except Exception, e:
             assert 0
         thread.gc_thread_die()
Esempio n. 2
0
 def bootstrap():
     # Note that when this runs, we already hold the GIL.  This is ensured
     # by rffi's callback mecanism: we are a callback for the
     # c_thread_start() external function.
     rthread.gc_thread_start()
     space = bootstrapper.space
     w_callable = bootstrapper.w_callable
     args = bootstrapper.args
     bootstrapper.nbthreads += 1
     bootstrapper.release()
     # run!
     try:
         bootstrapper.run(space, w_callable, args)
         # done
     except Exception as e:
         # oups! last-level attempt to recover.
         try:
             STDERR = 2
             os.write(STDERR, "Thread exited with ")
             os.write(STDERR, str(e))
             os.write(STDERR, "\n")
         except OSError:
             pass
     bootstrapper.nbthreads -= 1
     rthread.gc_thread_die()
Esempio n. 3
0
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     revdb.stop_point()
     _sleep(2)
     revdb.stop_point()
     rthread.gc_thread_die()
Esempio n. 4
0
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     print "BB"
     _sleep(2)
     print "BBB"
     rthread.gc_thread_die()
Esempio n. 5
0
 def bootstrap():
     # Note that when this runs, we already hold the GIL.  This is ensured
     # by rffi's callback mecanism: we are a callback for the
     # c_thread_start() external function.
     rthread.gc_thread_start()
     space = bootstrapper.space
     w_callable = bootstrapper.w_callable
     args = bootstrapper.args
     bootstrapper.nbthreads += 1
     bootstrapper.release()
     # run!
     try:
         bootstrapper.run(space, w_callable, args)
         # done
     except Exception as e:
         # oups! last-level attempt to recover.
         try:
             STDERR = 2
             os.write(STDERR, "Thread exited with ")
             os.write(STDERR, str(e))
             os.write(STDERR, "\n")
         except OSError:
             pass
     bootstrapper.nbthreads -= 1
     rthread.gc_thread_die()
Esempio n. 6
0
 def bootstrap():
     rthread.gc_thread_start()
     _sleep(1)
     ec = EC(4567)
     raw_thread_local.set(ec)
     print raw_thread_local.get().value
     assert raw_thread_local.get() is ec
     rthread.gc_thread_die()
Esempio n. 7
0
def PyThreadState_Clear(space, tstate):
    """Reset all information in a thread state object.  The global
    interpreter lock must be held."""
    Py_DecRef(space, tstate.c_dict)
    tstate.c_dict = lltype.nullptr(PyObject.TO)
    space.threadlocals.leave_thread(space)
    space.getexecutioncontext().cleanup_cpyext_state()
    rthread.gc_thread_die()
Esempio n. 8
0
def PyThreadState_Clear(space, tstate):
    """Reset all information in a thread state object.  The global
    interpreter lock must be held."""
    if not space.config.translation.thread:
        raise NoThreads
    Py_DecRef(space, tstate.c_dict)
    tstate.c_dict = lltype.nullptr(PyObject.TO)
    space.threadlocals.leave_thread(space)
    space.getexecutioncontext().cleanup_cpyext_state()
    rthread.gc_thread_die()
Esempio n. 9
0
 def bootstrap():
     rthread.gc_thread_start()
     childpid = run_in_thread()
     gc.collect()  # collect both in the child and in the parent
     gc.collect()
     gc.collect()
     if childpid == 0:
         os.write(state.write_end, 'c')  # "I did not die!" from child
     else:
         os.write(state.write_end, 'p')  # "I did not die!" from parent
     rthread.gc_thread_die()
Esempio n. 10
0
 def bootstrap():
     rthread.gc_thread_start()
     childpid = run_in_thread()
     gc.collect()        # collect both in the child and in the parent
     gc.collect()
     gc.collect()
     if childpid == 0:
         os.write(state.write_end, 'c')   # "I did not die!" from child
     else:
         os.write(state.write_end, 'p')   # "I did not die!" from parent
     rthread.gc_thread_die()
Esempio n. 11
0
class Bootstrapper(object):
    "A global container used to pass information to newly starting threads."

    # Passing a closure argument to rthread.start_new_thread() would be
    # theoretically nicer, but comes with messy memory management issues.
    # This is much more straightforward.

    nbthreads = 0

    # The following lock is held whenever the fields
    # 'bootstrapper.w_callable' and 'bootstrapper.args' are in use.
    lock = None
    args = None
    w_callable = None

    @staticmethod
    def setup(space):
        if bootstrapper.lock is None:
            try:
                bootstrapper.lock = rthread.allocate_lock()
            except rthread.error:
                raise wrap_thread_error(space, "can't allocate bootstrap lock")

    @staticmethod
    def reinit():
        bootstrapper.lock = None
        bootstrapper.nbthreads = 0
        bootstrapper.w_callable = None
        bootstrapper.args = None

    def _cleanup_(self):
        self.reinit()

    def bootstrap():
        # Note that when this runs, we already hold the GIL.  This is ensured
        # by rffi's callback mecanism: we are a callback for the
        # c_thread_start() external function.
        rthread.gc_thread_start()
        space = bootstrapper.space
        w_callable = bootstrapper.w_callable
        args = bootstrapper.args
        bootstrapper.nbthreads += 1
        bootstrapper.release()
        # run!
        try:
            bootstrapper.run(space, w_callable, args)
            # done
        except Exception, e:
            # oups! last-level attempt to recover.
            try:
                STDERR = 2
                os.write(STDERR, "Thread exited with ")
                os.write(STDERR, str(e))
                os.write(STDERR, "\n")
            except OSError:
                pass
        bootstrapper.nbthreads -= 1
        rthread.gc_thread_die()
Esempio n. 12
0
    def test_one_thread(self, skew=+1):
        from rpython.rlib.debug import debug_print
        if self.bigtest:
            N = 100000
            skew *= 25000
        else:
            N = 100
            skew *= 25
        space = FakeSpace()

        class State:
            pass

        state = State()

        def runme(main=False):
            j = 0
            for i in range(N + [-skew, skew][main]):
                state.datalen1 += 1  # try to crash if the GIL is not
                state.datalen2 += 1  # correctly acquired
                state.data.append((thread.get_ident(), i))
                state.datalen3 += 1
                state.datalen4 += 1
                assert state.datalen1 == len(state.data)
                assert state.datalen2 == len(state.data)
                assert state.datalen3 == len(state.data)
                assert state.datalen4 == len(state.data)
                debug_print(main, i, state.datalen4)
                rgil.yield_thread()
                assert i == j
                j += 1

        def bootstrap():
            try:
                runme()
            except Exception, e:
                assert 0
            thread.gc_thread_die()
Esempio n. 13
0
 def bootstrap():
     try:
         runme()
     except Exception as e:
         assert 0
     thread.gc_thread_die()
Esempio n. 14
0
 def bootstrap():
     rthread.gc_thread_start()
     check_errno(42)
     state.xlist.append(Cons(123, Cons(456, None)))
     gc.collect()
     rthread.gc_thread_die()
Esempio n. 15
0
def bootstrap():
    rthread.gc_thread_start()
    fn = bootstrapper.fn()
    bootstrapper.release()
    safe_invoke(fn, [])
    rthread.gc_thread_die()
Esempio n. 16
0
 def bootstrap():
     try:
         runme()
     except Exception as e:
         assert 0
     thread.gc_thread_die()
Esempio n. 17
0
 def bootstrap():
     rthread.gc_thread_start()
     check_errno(42)
     state.xlist.append(Cons(123, Cons(456, None)))
     gc.collect()
     rthread.gc_thread_die()
Esempio n. 18
0
def bootstrap():
    rthread.gc_thread_start()
    fn = bootstrapper.fn()
    bootstrapper.release()
    fn.invoke([])
    rthread.gc_thread_die()