主线程为什么不使用使用pthread_getattr_np?
(1)man pthread_getattr_np的ERRORS里有提到:
In addition, if thread refers to the main thread, then
pthread_getattr_np() can fail because of errors from various
underlying calls: fopen(3), if /proc/self/maps can't be opened;
and getrlimit(2), if the RLIMIT_STACK resource limit is not
supported.
(2)主线程使用pthread_getattr_np也是相当耗时,貌似也是需要解析/proc/self/maps,并且不止解析/proc/self/maps。
主线程第一次获取栈顶/栈底时会一个字节一个字节的读操作,这样会相当耗时,现在修改为逐行读取,粗略估算速度可提高10倍。
主线程为什么不使用使用pthread_getattr_np? (1)man pthread_getattr_np的ERRORS里有提到: In addition, if thread refers to the main thread, then pthread_getattr_np() can fail because of errors from various underlying calls: fopen(3), if /proc/self/maps can't be opened; and getrlimit(2), if the RLIMIT_STACK resource limit is not supported. (2)主线程使用pthread_getattr_np也是相当耗时,貌似也是需要解析/proc/self/maps,并且不止解析/proc/self/maps。
测试机型: 三星SM-G570F CPU架构armeabi-v7a Android版本7.0 测试OK LG-H422 CPU架构armeabi-v7a Android版本5.0.1 测试OK 三星SM-N910F CPU架构aarmeabi-v7a Android版本4.4.2 测试OK
修改前后耗时对比: