Beispiel #1
0
def stack_size(space, size=0):
    """stack_size([size]) -> size

Return the thread stack size used when creating new threads.  The
optional size argument specifies the stack size (in bytes) to be used
for subsequently created threads, and must be 0 (use platform or
configured default) or a positive integer value of at least 32,768 (32k).
If changing the thread stack size is unsupported, a ThreadError
exception is raised.  If the specified size is invalid, a ValueError
exception is raised, and the stack size is unmodified.  32k bytes
is currently the minimum supported stack size value to guarantee
sufficient stack space for the interpreter itself.

Note that some platforms may have particular restrictions on values for
the stack size, such as requiring a minimum stack size larger than 32kB or
requiring allocation in multiples of the system memory page size
- platform documentation should be referred to for more information
(4kB pages are common; using multiples of 4096 for the stack size is
the suggested approach in the absence of more specific information)."""
    if size < 0:
        raise OperationError(space.w_ValueError,
                             space.wrap("size must be 0 or a positive value"))
    old_size = rthread.get_stacksize()
    error = rthread.set_stacksize(size)
    if error == -1:
        raise oefmt(space.w_ValueError, "size not valid: %d bytes", size)
    if error == -2:
        raise wrap_thread_error(space, "setting stack size not supported")
    return space.wrap(old_size)
Beispiel #2
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = rthread.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 = rthread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = rthread.start_new_thread(bootstrap, ())
     ident2 = rthread.start_new_thread(bootstrap, ())
     ident3 = rthread.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
Beispiel #3
0
def stack_size(space, size=0):
    """stack_size([size]) -> size

Return the thread stack size used when creating new threads.  The
optional size argument specifies the stack size (in bytes) to be used
for subsequently created threads, and must be 0 (use platform or
configured default) or a positive integer value of at least 32,768 (32k).
If changing the thread stack size is unsupported, a ThreadError
exception is raised.  If the specified size is invalid, a ValueError
exception is raised, and the stack size is unmodified.  32k bytes
is currently the minimum supported stack size value to guarantee
sufficient stack space for the interpreter itself.

Note that some platforms may have particular restrictions on values for
the stack size, such as requiring a minimum stack size larger than 32kB or
requiring allocation in multiples of the system memory page size
- platform documentation should be referred to for more information
(4kB pages are common; using multiples of 4096 for the stack size is
the suggested approach in the absence of more specific information)."""
    if size < 0:
        raise oefmt(space.w_ValueError, "size must be 0 or a positive value")
    old_size = rthread.get_stacksize()
    error = rthread.set_stacksize(size)
    if error == -1:
        raise oefmt(space.w_ValueError, "size not valid: %d bytes", size)
    if error == -2:
        raise wrap_thread_error(space, "setting stack size not supported")
    return space.newint(old_size)
Beispiel #4
0
 def entry_point(argv):
     os.write(1, "hello world\n")
     error = rthread.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 = rthread.allocate_ll_lock()
     after()
     state.count = 0
     invoke_around_extcall(before, after)
     ident1 = rthread.start_new_thread(bootstrap, ())
     ident2 = rthread.start_new_thread(bootstrap, ())
     ident3 = rthread.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