Home > Enterprise >  Is OutputDebugString thread safe?
Is OutputDebugString thread safe?

Time:02-08

In my code I call these methods at various places to send diagnostic output to 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());
}

Is the method OutputDebugStringA() thread safe or could it mix messages from multiple threads being output at the same time?

If not would it be sufficient and a good idea to create a static member variable of std::mutex and lock this in my two methods above?

CodePudding user response:

Yes it is thread safe. It uses a mutex and events. Implementation details here.

  •  Tags:  
  • Related