首页 > 移动平台 > 详细

安卓线程使用问题

时间:2015-10-16 00:59:42      阅读:314      评论:0      收藏:0      [点我收藏+]

 

 

笔者今天使用c++ 11的 std::thread在安卓设备上来创建线程控制网络异步发送,发现线程启动就马上闪退,估计是安卓设备上不支持c++11的线程库,或者安卓系统版本过低,所以还是用回以前的pthread_create来创建线程,以下是三种创建线程的方法以及对应使用方法:

 std::thread方法:(支持windowsphone,windowsRT,ios,mac平台)

std::thread m_thread = std::thread(&Upgrade::requestHttp,this);

   m_thread.detach();

 

pthread_create方法:(支持Unix、Linux、Mac OS X、IOS、安卓)

pthread_t _thread;

pthread_create(&_thread, NULL, &Upgrade::requestHttp, this);

pthread_detach(_thread);

 

CreateThread方法:(支持windows pc平台)

CreateThread(NULL,          // default security attributes

                 0,             // use default stack size

                 &Upgrade::requestHttp,   // thread function name

                 this,          // argument to thread function

                 0,             // use default creation flags

                 NULL);

 

转载请注明出处,from 博客园 HemJohn

 

安卓线程使用问题

原文:http://www.cnblogs.com/HemJohn/p/4883981.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!