在我的代码中,我在不同的地方调用这些方法将诊断输出发送到DbgView
inline void dbg_info(std::string s) {
std::stringstream ss;
ss << "INFO:" << std::this_thread::get_id() << ": " << s << std::endl;
OutputDebugStringA(ss.str().c_str());
}
inline void dbg_err(std::string s) {
std::stringstream ss;
ss << "ERROR:" << std::this_thread::get_id() << ": " << s << std::endl;
OutputDebugStringA(ss.str().c_str());
}方法OutputDebugStringA()线程安全吗?还是可以将来自多个线程的消息同时输出?
如果不是,创建std::mutex的静态成员变量并将其锁定在上面的两个方法中是否足够,也是一个好主意?
发布于 2022-02-07 15:24:08
是的,线是安全的。它使用互斥和事件。实现细节这里。
https://stackoverflow.com/questions/71020560
复制相似问题