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
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
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
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.Lock(ll_thread.allocate_ll_lock()) state.count = 0 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: state.ll_lock.acquire(True) if state.count == 3: break state.ll_lock.release() time.sleep(0.1) # 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
def setup_threads(self, space): """Enable threads in the object space, if they haven't already been.""" if not self.ll_GIL: try: self.ll_GIL = thread.allocate_ll_lock() except thread.error: raise wrap_thread_error(space, "can't allocate GIL") thread.acquire_NOAUTO(self.ll_GIL, True) self.enter_thread(space) # setup the main thread 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.ll_GIL = self.ll_GIL spacestate.actionflag = space.actionflag invoke_around_extcall(before_external_call, after_external_call) return result
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
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
def reinit_threads(self, space): if self.ll_GIL: self.ll_GIL = thread.allocate_ll_lock() thread.acquire_NOAUTO(self.ll_GIL, True) self.enter_thread(space)
def PyThread_allocate_lock(space): lock = ll_thread.allocate_ll_lock() return rffi.cast(LOCKP, lock)