可能只与Visual C ++有关。
当我正在开发一个运行多个线程的程序时,每个程序都使用std :: ostream,主要是:
for (auto& work: works)
{
threadVec.push_back(new thread([work](){working(work);}))
}
void working(Work work)
{
std::stringstream ss;
for (auto& task:work)
{
// massive done here
ss << 1u << 2.0 << "str" << task.GetID();
}
}
一旦运行,大多数线程都停留在CRT函数_lock_locales()
,并且线程堆栈看起来像:
ntdll!<address>()
program.exe!__acrt_lock()
program.exe!_lock_locales()
......
program.exe!std::use_facet()
......
program.exe!std::basic_ostream<>::operator << (int _Val)
我的问题是:是否可以避免使用此锁(等于避免使用facet imo),使每个线程更快地工作?
不擅长英语,非常感谢你的帮助。