Opened 7 years ago

Last modified 3 years ago

#791 new discussion

lock ostreams

Reported by: Peter Owned by: Peter
Priority: minor Milestone: yat 0.x+
Component: utility Version:
Keywords: Cc:

Description

I have a program in which the different threads send some output to std::clog and quite often the output is intermingled since an output typically is generated via multiple calls to operator<<.

Would be nice to have an easy way to lock access to ostreams in particular the global instances std::cout and std::clog.

Perhaps an interface could look something like this:

LockMe(std::clog) << "Hey my name is " << who_am_I << "\n";

where the LockMe is a class constructor and std::clog is the lock is released in destructor of same class, i.e., after "\n" has been passed to std::clog.

Change History (1)

comment:1 Changed 3 years ago by Peter

There's a proposal for C++20 on synchronized ostreams: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0053r7.pdf

Note: See TracTickets for help on using tickets.