Is cout synchronized/thread-safe?

后端 未结 4 1954
闹比i
闹比i 2020-11-22 05:50

In general I assume that streams are not synchronized, it is up to the user to do appropriate locking. However, do things like cout get special treatment in the

4条回答
  •  别那么骄傲
    2020-11-22 06:19

    The C++ Standard does not specify whether writing to streams is thread-safe, but usually it's not.

    www.techrepublic.com/article/use-stl-streams-for-easy-c-plus-plus-thread-safe-logging

    and also: Are standard output streams in C++ thread-safe (cout, cerr, clog)?

    UPDATE

    Please have a look at @Martinho Fernandes' answer to know about what the new standard C++11 tells about this.

提交回复
热议问题