예제 #1
0
 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
 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
 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
        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
 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
 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
 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
        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
        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")