安卓线程使用问题

笔者今天使用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

原文地址:https://www.cnblogs.com/HemJohn/p/4883981.html