我使用的cocos2d-x 3.0 版本,使用到了新的c++ 11的线程
std::thread t(thread_funcation,this);
t.detach();
用这种方式创建了线程
在thread_funcation中,线程直接退出后
void* NetDatabase::thread_funcation(void *arg)
{
CURL *curl;
CURLcode res;
NetDatabase* pNetDB=(NetDatabase*)arg;
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpWriteString);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, pNetDB);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 15);
curl_easy_setopt(curl, CURLOPT_URL, “192.168.1.108:8080/lumiserv/test”)
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, “type=getandupdate&name=xx14&score=99999”); //更改数据同时获取服务器数据
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == 0)
{
log(" CallBack Succeed.最终数据 %s",pNetDB->m_netData.c_str());
}
else
{
CCLOG(“error code %d”,res);
}
}
else
{
CCLOG(“no curl”);
}
!
return NULL;
}
!
在win32下运行的很正常
但是在android,打印完返回的数据后就崩溃了
)
)