【发布时间】:2015-02-23 12:26:37
【问题描述】:
在下面的代码中,main() 函数调用 request() 函数,该函数调用了 mm_th_done_cb() 的 th_request_async() 函数。
只有在 mm_th_done_cb() 执行后才能在 main 中继续进行的最佳和有效方法是什么。
虚拟代码
int mm_th_done_cb(int error_code, th_result_s* th_result, void* user_data)
{
return 0;
}
void request()
{
th_request_s MyItemInfo;
strncpy(MyItemInfo.origin_path, szUrl, 1024+1);
MyItemInfo.orientation = 0;
MyItemInfo.func = mm_th_done_cb;
MyItemInfo.used_cache = 1;
th_request_async(MyItemInfo);
}
int main()
{
request();
// Here I need to do something only after mm_th_done_cb() has been excuted.
}
【问题讨论】:
-
在 free 语句之前将调用设为 NULL。
标签: c++ multithreading synchronization