Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Get the default stack size of new pthread threads
- """
- import ctypes, ctypes.util
- libc = ctypes.CDLL(ctypes.util.find_library("c"))
- pthread_attr_getstacksize = libc.pthread_attr_getstacksize
- pthread_attr_getstacksize.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_size_t)]
- pthread_attr_getstacksize.restype = ctypes.c_int
- pthread_self = libc.pthread_self
- pthread_self.restype = ctypes.c_void_p
- pthread_attr_init = libc.pthread_attr_init
- pthread_attr_init.restype = ctypes.c_int
- pthread_attr_init.argtypes = [ctypes.c_void_p]
- pthread_attr_destroy = libc.pthread_attr_destroy
- pthread_attr_destroy.argtypes = [ctypes.c_void_p]
- pthread_attr_destroy.restype = ctypes.c_int
- attr = (ctypes.c_char * 1024)() # buffer with probably sufficient size
- if pthread_attr_init(attr):
- raise OSError(ctypes.get_errno())
- size = ctypes.c_size_t(0)
- status = pthread_attr_getstacksize(
- attr, ctypes.pointer(size)
- )
- print("Status:", status, ", size:", size.value)
- pthread_attr_destroy(attr)
Add Comment
Please, Sign In to add comment