コード例 #1
0
ファイル: test_standalone.py プロジェクト: xx312022850/pypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     ident1 = ll_thread.start_new_thread(bootstrap, ())
     ident2 = ll_thread.start_new_thread(bootstrap, ())
     #
     gc.collect()
     #
     ident3 = ll_thread.start_new_thread(bootstrap, ())
     ident4 = ll_thread.start_new_thread(bootstrap, ())
     ident5 = ll_thread.start_new_thread(bootstrap, ())
     # wait for the 5 threads to finish
     while True:
         gc.collect()
         if len(state.xlist) == 5:
             break
         time.sleep(0.1)  # invokes before/after
     # check that the malloced structures were not overwritten
     assert x2.head == 51
     assert x2.tail.head == 62
     assert x2.tail.tail.head == 74
     assert x2.tail.tail.tail is None
     # check the structures produced by the threads
     for i in range(5):
         assert state.xlist[i].head == 123
         assert state.xlist[i].tail.head == 456
         assert state.xlist[i].tail.tail is None
         os.write(1, "%d ok\n" % (i + 1))
     return 0
コード例 #2
0
ファイル: test_standalone.py プロジェクト: ieure/pypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = ll_thread.set_stacksize(int(argv[1]))
     if error != 0:
         os.write(2, "set_stacksize(%d) returned %d\n" % (
             int(argv[1]), error))
         raise AssertionError
     # malloc a bit
     s1 = State(); s2 = State(); s3 = State()
     s1.x = 0x11111111; s2.x = 0x22222222; s3.x = 0x33333333
     # start 3 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = ll_thread.start_new_thread(bootstrap, ())
     ident2 = ll_thread.start_new_thread(bootstrap, ())
     ident3 = ll_thread.start_new_thread(bootstrap, ())
     # wait for the 3 threads to finish
     while True:
         if state.count == 3:
             break
         time.sleep(0.1)      # invokes before/after
     # check that the malloced structures were not overwritten
     assert s1.x == 0x11111111
     assert s2.x == 0x22222222
     assert s3.x == 0x33333333
     os.write(1, "done\n")
     return 0
コード例 #3
0
ファイル: test_standalone.py プロジェクト: xx312022850/pypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = ll_thread.set_stacksize(int(argv[1]))
     assert error == 0
     # malloc a bit
     s1 = State()
     s2 = State()
     s3 = State()
     s1.x = 0x11111111
     s2.x = 0x22222222
     s3.x = 0x33333333
     # start 3 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = ll_thread.start_new_thread(bootstrap, ())
     ident2 = ll_thread.start_new_thread(bootstrap, ())
     ident3 = ll_thread.start_new_thread(bootstrap, ())
     # wait for the 3 threads to finish
     while True:
         if state.count == 3:
             break
         time.sleep(0.1)  # invokes before/after
     # check that the malloced structures were not overwritten
     assert s1.x == 0x11111111
     assert s2.x == 0x22222222
     assert s3.x == 0x33333333
     os.write(1, "done\n")
     return 0
コード例 #4
0
ファイル: test_ll_thread.py プロジェクト: gorakhargosh/pypy
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            # When not translated it does not work around time.sleep(),
            # so we have to call them manually for this test.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                if not we_are_translated(): before_extcall()
                time.sleep(0.01)
                if not we_are_translated(): after_extcall()

            if not we_are_translated(): before_extcall()
            time.sleep(0.1)
            if not we_are_translated(): after_extcall()

            return len(state.answers)
コード例 #5
0
ファイル: test_standalone.py プロジェクト: ieure/pypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     ident1 = new_thread()
     ident2 = new_thread()
     #
     gc.collect()
     #
     ident3 = new_thread()
     ident4 = new_thread()
     ident5 = new_thread()
     # wait for the 5 threads to finish
     while True:
         gc.collect()
         if len(state.xlist) == 5:
             break
         time.sleep(0.1)      # invokes before/after
     # check that the malloced structures were not overwritten
     assert x2.head == 51
     assert x2.tail.head == 62
     assert x2.tail.tail.head == 74
     assert x2.tail.tail.tail is None
     # check the structures produced by the threads
     for i in range(5):
         assert state.xlist[i].head == 123
         assert state.xlist[i].tail.head == 456
         assert state.xlist[i].tail.tail is None
         os.write(1, "%d ok\n" % (i+1))
     return 0
コード例 #6
0
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            # When not translated it does not work around time.sleep(),
            # so we have to call them manually for this test.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                if not we_are_translated(): before_extcall()
                time.sleep(0.01)
                if not we_are_translated(): after_extcall()

            if not we_are_translated(): before_extcall()
            time.sleep(0.1)
            if not we_are_translated(): after_extcall()

            return len(state.answers)
コード例 #7
0
ファイル: gil.py プロジェクト: antoine1fr/pygirl
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if self.GIL is None:
            try:
                self.GIL = thread.allocate_lock_NOAUTO()
            except thread.error:
                raise wrap_thread_error(space, "can't allocate GIL")
            self.enter_thread(space)   # setup the main thread
            # add the GIL-releasing callback as an action on the space
            space.pending_actions.append(GILReleaseAction(self))
            result = True
        else:
            result = False      # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        spacestate.GIL = self.GIL
        invoke_around_extcall(before_external_call, after_external_call)
        return result
コード例 #8
0
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if self.GIL is None:
            try:
                self.GIL = thread.allocate_lock_NOAUTO()
            except thread.error:
                raise wrap_thread_error(space, "can't allocate GIL")
            self.enter_thread(space)  # setup the main thread
            # add the GIL-releasing callback as an action on the space
            space.pending_actions.append(GILReleaseAction(self))
            result = True
        else:
            result = False  # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        spacestate.GIL = self.GIL
        invoke_around_extcall(before_external_call, after_external_call)
        return result
コード例 #9
0
ファイル: gil.py プロジェクト: Debug-Orz/Sypy
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if not self.gil_ready:
            if not thread.gil_allocate():
                raise wrap_thread_error(space, "can't allocate GIL")
            self.gil_ready = True
            result = True
        else:
            result = False      # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        invoke_around_extcall(before_external_call, after_external_call)
        return result
コード例 #10
0
ファイル: gil.py プロジェクト: nipengadmaster/pypy
    def setup_threads(self, space):
        """Enable threads in the object space, if they haven't already been."""
        if not self.gil_ready:
            if not thread.gil_allocate():
                raise wrap_thread_error(space, "can't allocate GIL")
            self.gil_ready = True
            result = True
        else:
            result = False  # already set up

        # add the GIL-releasing callback around external function calls.
        #
        # XXX we assume a single space, but this is not quite true during
        # testing; for example, if you run the whole of test_lock you get
        # a deadlock caused by the first test's space being reused by
        # test_lock_again after the global state was cleared by
        # test_compile_lock.  As a workaround, we repatch these global
        # fields systematically.
        invoke_around_extcall(before_external_call, after_external_call)
        return result
コード例 #11
0
ファイル: test_standalone.py プロジェクト: ieure/pypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     state.deleted = 0
     state.read_end, state.write_end = os.pipe()
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     start_all_threads()
     # force freeing
     gc.collect()
     gc.collect()
     gc.collect()
     # return everything that was written to the pipe so far,
     # followed by the final dot.
     os.write(state.write_end, '.')
     result = os.read(state.read_end, 256)
     os.write(1, "got: %s\n" % result)
     return 0
コード例 #12
0
ファイル: test_standalone.py プロジェクト: njues/Sypy
 def entry_point(argv):
     os.write(1, "hello world\n")
     state.xlist = []
     state.deleted = 0
     state.read_end, state.write_end = os.pipe()
     x2 = Cons(51, Cons(62, Cons(74, None)))
     # start 5 new threads
     state.ll_lock = ll_thread.allocate_ll_lock()
     after()
     invoke_around_extcall(before, after)
     start_all_threads()
     # force freeing
     gc.collect()
     gc.collect()
     gc.collect()
     # return everything that was written to the pipe so far,
     # followed by the final dot.
     os.write(state.write_end, '.')
     result = os.read(state.read_end, 256)
     os.write(1, "got: %s\n" % result)
     return 0
コード例 #13
0
ファイル: test_ll_thread.py プロジェクト: Debug-Orz/Sypy
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                time.sleep(0.01)

            time.sleep(0.1)

            return len(state.answers)
コード例 #14
0
ファイル: test_ll_thread.py プロジェクト: nipengadmaster/pypy
        def f():
            state.gil = allocate_ll_lock()
            acquire_NOAUTO(state.gil, True)
            state.bootstrapping = allocate_lock()
            state.answers = []
            state.finished = 0
            # the next line installs before_extcall() and after_extcall()
            # to be called automatically around external function calls.
            invoke_around_extcall(before_extcall, after_extcall)

            g(10, 1)
            done = False
            willing_to_wait_more = 2000
            while not done:
                if not willing_to_wait_more:
                    break
                willing_to_wait_more -= 1
                done = len(state.answers) == expected

                time.sleep(0.01)

            time.sleep(0.1)

            return len(state.answers)
コード例 #15
0
 def f():
     os.write(write_fd, "-")
     invoke_around_extcall(before, after)
     os.write(write_fd, "E")
コード例 #16
0
ファイル: test_rffi.py プロジェクト: Debug-Orz/Sypy
 def f():
     os.write(write_fd, "-")
     invoke_around_extcall(before, after)
     os.write(write_fd, "E")