示例#1
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
示例#2
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
示例#3
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
示例#4
0
	def start(self):
		#ll_acquire_lock(boot.lock)
		boot.lock.acquire()
		boot.body = self
		boot.proc = self.subclass.RUN
		#boot.bootstrap()
		start_new_thread(boot.bootstrap, ())
 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
示例#6
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
示例#7
0
def start_new_thread(space, w_callable, w_args, w_kwargs=NoneNotWrapped):
    """Start a new thread and return its identifier.  The thread will call the
function with positional arguments from the tuple args and keyword arguments
taken from the optional dictionary kwargs.  The thread exits when the
function returns; the return value is ignored.  The thread will also exit
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
    setup_threads(space)
    if not space.is_true(space.isinstance(w_args, space.w_tuple)):
        raise OperationError(space.w_TypeError,
                             space.wrap("2nd arg must be a tuple"))
    if w_kwargs is not None and not space.is_true(
            space.isinstance(w_kwargs, space.w_dict)):
        raise OperationError(
            space.w_TypeError,
            space.wrap("optional 3rd arg must be a dictionary"))
    if not space.is_true(space.callable(w_callable)):
        raise OperationError(space.w_TypeError,
                             space.wrap("first arg must be callable"))

    args = Arguments.frompacked(space, w_args, w_kwargs)
    bootstrapper.acquire(space, w_callable, args)
    try:
        try:
            thread.gc_thread_prepare()  # (this has no effect any more)
            ident = thread.start_new_thread(bootstrapper.bootstrap, ())
        except Exception, e:
            bootstrapper.release()  # normally called by the new thread
            raise
    except thread.error:
        raise wrap_thread_error(space, "can't start new thread")
    return space.wrap(ident)
示例#8
0
def start_new_thread(space, w_callable, w_args, w_kwargs=NoneNotWrapped):
    """Start a new thread and return its identifier.  The thread will call the
function with positional arguments from the tuple args and keyword arguments
taken from the optional dictionary kwargs.  The thread exits when the
function returns; the return value is ignored.  The thread will also exit
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
    setup_threads(space)
    if not space.is_true(space.isinstance(w_args, space.w_tuple)): 
        raise OperationError(space.w_TypeError, 
                space.wrap("2nd arg must be a tuple")) 
    if w_kwargs is not None and not space.is_true(space.isinstance(w_kwargs, space.w_dict)): 
        raise OperationError(space.w_TypeError, 
                space.wrap("optional 3rd arg must be a dictionary")) 
    if not space.is_true(space.callable(w_callable)):
        raise OperationError(space.w_TypeError, 
                space.wrap("first arg must be callable"))

    args = Arguments.frompacked(space, w_args, w_kwargs)
    bootstrapper.acquire(space, w_callable, args)
    try:
        try:
            thread.gc_thread_prepare()
            ident = thread.start_new_thread(bootstrapper.bootstrap, ())
        except Exception, e:
            bootstrapper.release()     # normally called by the new thread
            raise
    except thread.error:
        raise wrap_thread_error(space, "can't start new thread")
    return space.wrap(ident)
示例#9
0
 def f():
     state.data = []
     state.threadlocals = gil.GILThreadLocals()
     state.threadlocals.setup_threads(space)
     thread.gc_thread_prepare()
     subident = thread.start_new_thread(bootstrap, ())
     mainident = thread.get_ident()
     runme()
     still_waiting = 3000
     while len(state.data) < 2*N:
         if not still_waiting:
             raise ValueError("time out")
         still_waiting -= 1
         if not we_are_translated(): gil.before_external_call()
         time.sleep(0.01)
         if not we_are_translated(): gil.after_external_call()
     i1 = i2 = 0
     for tid, i in state.data:
         if tid == mainident:
             assert i == i1; i1 += 1
         elif tid == subident:
             assert i == i2; i2 += 1
         else:
             assert 0
     assert i1 == N
     assert i2 == N
     return len(state.data)
示例#10
0
 def f():
     state.data = []
     state.datalen1 = 0
     state.datalen2 = 0
     state.datalen3 = 0
     state.datalen4 = 0
     state.threadlocals = gil.GILThreadLocals()
     state.threadlocals.setup_threads(space)
     thread.gc_thread_prepare()
     subident = thread.start_new_thread(bootstrap, ())
     mainident = thread.get_ident()
     runme(True)
     still_waiting = 3000
     while len(state.data) < 2*N:
         debug_print(len(state.data))
         if not still_waiting:
             raise ValueError("time out")
         still_waiting -= 1
         if not we_are_translated(): gil.before_external_call()
         time.sleep(0.01)
         if not we_are_translated(): gil.after_external_call()
     debug_print("leaving!")
     i1 = i2 = 0
     for tid, i in state.data:
         if tid == mainident:
             assert i == i1; i1 += 1
         elif tid == subident:
             assert i == i2; i2 += 1
         else:
             assert 0
     assert i1 == N + skew
     assert i2 == N - skew
     return len(state.data)
示例#11
0
def start_new_thread(space, w_callable, w_args, w_kwargs=NoneNotWrapped):
    """Start a new thread and return its identifier.  The thread will call the
function with positional arguments from the tuple args and keyword arguments
taken from the optional dictionary kwargs.  The thread exits when the
function returns; the return value is ignored.  The thread will also exit
when the function raises an unhandled exception; a stack trace will be
printed unless the exception is SystemExit."""
    setup_threads(space)
    if not space.is_true(space.isinstance(w_args, space.w_tuple)):
        raise OperationError(space.w_TypeError,
                             space.wrap("2nd arg must be a tuple"))
    if w_kwargs is not None and not space.is_true(
            space.isinstance(w_kwargs, space.w_dict)):
        raise OperationError(
            space.w_TypeError,
            space.wrap("optional 3rd arg must be a dictionary"))
    if not space.is_true(space.callable(w_callable)):
        raise OperationError(space.w_TypeError,
                             space.wrap("first arg must be callable"))

    args = Arguments.frompacked(space, w_args, w_kwargs)
    boot = Bootstrapper()
    boot.space = space
    boot.w_callable = w_callable
    boot.args = args
    try:
        ident = thread.start_new_thread(Bootstrapper.bootstrap, (boot, ))
    except thread.error:
        raise wrap_thread_error(space, "can't start new thread")
    return space.wrap(ident)
示例#12
0
def test_threaded_count(iterations, num_threads):
    # Warm up.
    count(1000)

    threads = []
    t0 = time.time()
    for _ in xrange(iterations):
		for _ in xrange(num_threads):
			threads.append(ll_thread.start_new_thread(count, ()))
    t1 = time.time()
    return t1 - t0
示例#13
0
 def new_thread():
     ll_thread.gc_thread_prepare()
     ident = ll_thread.start_new_thread(bootstrap, ())
     time.sleep(0.5)    # enough time to start, hopefully
     return ident
示例#14
0
 def new_thread():
     ll_thread.gc_thread_prepare()
     ident = ll_thread.start_new_thread(bootstrap, ())
     time.sleep(0.5)    # enough time to start, hopefully
     return ident