Guest User

Untitled

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. """
  2. Get the default stack size of new pthread threads
  3. """
  4.  
  5. import ctypes, ctypes.util
  6. libc = ctypes.CDLL(ctypes.util.find_library("c"))
  7.  
  8. pthread_attr_getstacksize = libc.pthread_attr_getstacksize
  9. pthread_attr_getstacksize.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_size_t)]
  10. pthread_attr_getstacksize.restype = ctypes.c_int
  11.  
  12. pthread_self = libc.pthread_self
  13. pthread_self.restype = ctypes.c_void_p
  14.  
  15. pthread_attr_init = libc.pthread_attr_init
  16. pthread_attr_init.restype = ctypes.c_int
  17. pthread_attr_init.argtypes = [ctypes.c_void_p]
  18.  
  19. pthread_attr_destroy = libc.pthread_attr_destroy
  20. pthread_attr_destroy.argtypes = [ctypes.c_void_p]
  21. pthread_attr_destroy.restype = ctypes.c_int
  22.  
  23. attr = (ctypes.c_char * 1024)() # buffer with probably sufficient size
  24.  
  25. if pthread_attr_init(attr):
  26. raise OSError(ctypes.get_errno())
  27.  
  28.  
  29. size = ctypes.c_size_t(0)
  30. status = pthread_attr_getstacksize(
  31. attr, ctypes.pointer(size)
  32. )
  33. print("Status:", status, ", size:", size.value)
  34.  
  35. pthread_attr_destroy(attr)
Add Comment
Please, Sign In to add comment