我正在编写一个C++程序,以使用C++ REST SDK与Internet进行交互。我有一个主要功能和一个Web通信功能。该代码类似于以下内容:完成其他函数完成之前的C++函数
void webCommunication(data, url)
{
//Communicate with the internet using the http_client
//Print output
}
int main()
{
//Obtain information from user
webCommunication(ans1, ans2);
system("PAUSE");
}
但是,似乎主要功能在web通信功能完成之前正在进行。如果我做webCommunication函数字符串类型,并有
cout << webCommunication(ans1, ans2) << endl;
但仍然暂停,然后打印检索到的数据。通常情况下,这会很好,希望我在后面的代码中引用返回的答案。如果网络通信未完成,则应用程序崩溃。有什么可以使用的wait_until函数吗?
更新:我尝试使用互斥建议没有成功。我也尝试将该函数作为一个线程启动,然后使用.join()仍然没有成功。
检查REST SDK是否有等待线程完成的函数。 – 2015-04-03 15:38:12