static std::mutex myttttMutex;
void addLock()
{
std::lock_guard<std::mutex> guard(myttttMutex);//加锁
}
void UpdateLoop(string str)
{
//doing...
addLock();//需要加锁的函数可以用 std::mutex
}
int nSize = strlist.size();
vector<std::thread> vthreads(nSize);
for (int i = 0; i < nSize; i++)//多线程同步执行
{
vthreads[i] = std::thread(UpdateLoop, strlist[i]);
}
for (auto &t : vthreads)//这里等待所有线程结束
{
t.join();
}