android上Bionic不支持pthread_cancel等函数
2013-05-27 17:07
274 查看
谷歌在Bionic中没有实现pthread_cancel、pthread_testcancel的函数主要出于线程安全性以及其他api实现简洁性等方面考虑。官方的说法如下:
pthread_cancel():
pthread_cancel() will *not* be supported in Bionic, because doing this would
involve making the C library significantly bigger for very little benefit.
Consider that:
- A proper implementation must insert pthread cancellation checks in a lot
of different places of the C library. And conformance is very difficult
to test properly.
- A proper implementation must also clean up resources, like releasing
memory, or unlocking mutexes, properly if the cancellation happens in a
complex function (e.g. inside gethostbyname() or fprintf() + complex
formatting rules). This tends to slow down the path of many functions.
- pthread cancellation cannot stop all threads: e.g. it can't do anything
against an infinite loop
- pthread cancellation itself has short-comings and isn't very portable
(see http://advogato.org/person/slamb/diary.html?start=49 for
example).
All of this is contrary to the Bionic design goals. If your code depends on
thread cancellation, please consider alternatives.
Note however that Bionic does implement pthread_cleanup_push() and
pthread_cleanup_pop(), which can be used to handle cleanups that happen when
a thread voluntarily exits through pthread_exit() or returning from its
main function.
杀死线程的功能肯定是要用的,解决的方法大概有两种:
1.主进程中设标志,线程查询标志,被置位后调用pthread_exit()退出;
2.用pthread_kill()代替,如这位哥们所述http://www.rosoo.net/a/201112/15523.html,安全性很差
其他pthread相关资料:
http://www.cnblogs.com/lijunamneg/archive/2013/01/25/2877211.html
http://my.oschina.net/u/178323/blog/32535
pthread_cancel():
pthread_cancel() will *not* be supported in Bionic, because doing this would
involve making the C library significantly bigger for very little benefit.
Consider that:
- A proper implementation must insert pthread cancellation checks in a lot
of different places of the C library. And conformance is very difficult
to test properly.
- A proper implementation must also clean up resources, like releasing
memory, or unlocking mutexes, properly if the cancellation happens in a
complex function (e.g. inside gethostbyname() or fprintf() + complex
formatting rules). This tends to slow down the path of many functions.
- pthread cancellation cannot stop all threads: e.g. it can't do anything
against an infinite loop
- pthread cancellation itself has short-comings and isn't very portable
(see http://advogato.org/person/slamb/diary.html?start=49 for
example).
All of this is contrary to the Bionic design goals. If your code depends on
thread cancellation, please consider alternatives.
Note however that Bionic does implement pthread_cleanup_push() and
pthread_cleanup_pop(), which can be used to handle cleanups that happen when
a thread voluntarily exits through pthread_exit() or returning from its
main function.
杀死线程的功能肯定是要用的,解决的方法大概有两种:
1.主进程中设标志,线程查询标志,被置位后调用pthread_exit()退出;
2.用pthread_kill()代替,如这位哥们所述http://www.rosoo.net/a/201112/15523.html,安全性很差
其他pthread相关资料:
http://www.cnblogs.com/lijunamneg/archive/2013/01/25/2877211.html
http://my.oschina.net/u/178323/blog/32535
相关文章推荐
- 【Cocos2dx通信(Http&Socket)相关编译到Android细节总结】编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- 相关编译到Android细节总结 编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- Cocos2dx通信(Http&Socket)相关编译到Android细节总结 编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_in
- 【Cocos2dx通信(Http&Socket)相关编译到Android细节总结】编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- 【Cocos2dx通信(Http&Socket)相关编译到Android细节总结】编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- 【Cocos2dx通信(Http&Socket)相关编译到Android细节总结】编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- Android bionic缺失pthread_cancel的解决方法
- android bionic缺失pthread_cancel的解决方法
- android bionic缺失pthread_cancel的解决方法
- android bionic缺失pthread_cancel的解决方法
- android bionic缺失pthread_cancel的解决方法
- android bionic缺失pthread_cancel的解决方法
- Android bionic缺失pthread_cancel的解决方法
- pthread_cancel函数注意事项
- pthread_cancel() NDK不支持
- 线程的取消pthread_cancel()函数(线程三)
- android ndk not support pthread_cancel
- 调用系统函数pthread_cancel取消进程的其他线程
- (android之sqlite二)常见Sqlite支持的Sql语句函数总结
- Android2.2:'pthread_rwlock_t' does not name a type: android 2.3版本以下不支持读写锁的解决办法