android ndk not support pthread_cancel
2014-08-15 12:14
302 查看
http://blog.csdn.net/typename/article/details/7794958
转载请注明: http://blog.csdn.net/typename/article/details/7794958
下面是google关于这个问题的说法:
Try changing your code so that your threads don't get stuck waiting
indefinitely for i/o. For example used conditional variables, select
or poll to wait for events, and be sure to create a 'stop-the-thread
event'. That's how any properly written code should be anyway
Another more rustic alternative is to either close/shutdown the file
descriptor or resource the thread is waiting on, or even use
pthread-kill to send a signal to the thread, since this sill make the
system call return with EINTR (you need to unblock the signal first
though)
In all cases, be sure to properly release resources when exiting thr
thread. 99% of the code that uses pthread_cancel I have seen leaks
memory, or even locks, in certain circumstances.
pthread_cancel可以说是一种暴力结束线程的方式,主线程或者A线程可以调用这个pthread_cancel ,kill掉其他线程。暴力意味着不优雅,若此时线程正在释放资源,释放线程锁,这时候有可能导致内存泄漏和deadlock等其他一些诡异现象。网上有人说用pthread_kill
+ 信号,我个人觉得这个还是挺好系统资源的。其实可以很简单的做到替换pthread_cancel的方法,通过开关变量来实现,当CPU时间片到来的时候,改变开关变量的值,让线程在释放各种资源后自动退出。
[cpp] view
plaincopy
static volatile bool switch_variable = true;
void ThreadCallback(void *param)
{
...
while(switch_variable)
{
...
}
elease some resource;
}
int main()
{
...
change switch_variable;
switch_variable = false;
...
return 0;
}
转载请注明: http://blog.csdn.net/typename/article/details/7794958
下面是google关于这个问题的说法:
Try changing your code so that your threads don't get stuck waiting
indefinitely for i/o. For example used conditional variables, select
or poll to wait for events, and be sure to create a 'stop-the-thread
event'. That's how any properly written code should be anyway
Another more rustic alternative is to either close/shutdown the file
descriptor or resource the thread is waiting on, or even use
pthread-kill to send a signal to the thread, since this sill make the
system call return with EINTR (you need to unblock the signal first
though)
In all cases, be sure to properly release resources when exiting thr
thread. 99% of the code that uses pthread_cancel I have seen leaks
memory, or even locks, in certain circumstances.
pthread_cancel可以说是一种暴力结束线程的方式,主线程或者A线程可以调用这个pthread_cancel ,kill掉其他线程。暴力意味着不优雅,若此时线程正在释放资源,释放线程锁,这时候有可能导致内存泄漏和deadlock等其他一些诡异现象。网上有人说用pthread_kill
+ 信号,我个人觉得这个还是挺好系统资源的。其实可以很简单的做到替换pthread_cancel的方法,通过开关变量来实现,当CPU时间片到来的时候,改变开关变量的值,让线程在释放各种资源后自动退出。
[cpp] view
plaincopy
static volatile bool switch_variable = true;
void ThreadCallback(void *param)
{
...
while(switch_variable)
{
...
}
elease some resource;
}
int main()
{
...
change switch_variable;
switch_variable = false;
...
return 0;
}
相关文章推荐
- android ndk not support pthread_cancel
- 【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
- 【Cocos2dx通信(Http&Socket)相关编译到Android细节总结】编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- Cocos2dx通信(Http&Socket)相关编译到Android细节总结 编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_in
- 相关编译到Android细节总结 编译加入curl关联lib与头文件 && 解决pthread的cancel函数NDK不支持,找不到sockaddr_i
- android真机上 conn.getOutputStream()异常 Does not support output
- android bionic缺失pthread_cancel的解决方法
- 解决NDK交叉编译 selected processor does not support ARM mode libtheora的错误
- pthread_cancel() NDK不支持
- 添加android-support-v4 错误 java.lang.ClassNotFoundException: android.support.v4.view.ViewPager in loade
- android bionic缺失pthread_cancel的解决方法
- NDK的错误ERROR: The device does not support the application's targetted CPU ABIs!解决方法
- ADT20新建项目Android Support library not installed问题
- 用ndk编写Android环境下的pthread多线程程序
- android bionic缺失pthread_cancel的解决方法
- android NDK JNI下有些函数could not be resolved
- android NDK JNI下有些函数could not be resolved
- android上Bionic不支持pthread_cancel等函数