Alex Rivera | Logout

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

Asked 2009-09-27T11:39:16.287
11

I know that there is no concept of threads in current C++, but this article is saying:

A typesafe, threadsafe, portable logging mechanism

.....

The fprintf() function is threadsafe, so even if this log is used from different threads, the output lines won't be scrambled.

What about cout, cerr and clog?

I think this question is applicable to all kind of stream types in C++ also, like fstream and stringstream.

Edit
Report

1 Answer

2

Since the current C++ standard doesn't even acknowledge that there are things called "threads", it certainly doesn't give any guarantees regarding thread-safety at all.

This is all implementation-defined.

answered 2009-09-27T12:11:12.637

Your Answer