H
Henryk
Ok, my question is a little system-related. C++ does not know anything
about threads, I know. But where else to ask?
Under linux with libstdc++.so.6 is writing to cout thread save or do I
need to make it thread safe by some kind of wrapper?
The impact to existing code should be minimal (at best a simple search
& replace).
Would something like this do:
inline std:stream &Wrapper::cout() {
Lock lock(mutex);
return std::cout;
}
And then use it like this
Wrapper::cout() << "print something" << "print more" << std::endl;
How long does the scoped lock protect the access to std::cout? The
mutex is released within lock's destructor, which is called after the
return statement.
I tested it in an VM environment and it worked as far as I visually
checked the output. But does it work for sure?
Thanks for any insights!
Henryk
about threads, I know. But where else to ask?
Under linux with libstdc++.so.6 is writing to cout thread save or do I
need to make it thread safe by some kind of wrapper?
The impact to existing code should be minimal (at best a simple search
& replace).
Would something like this do:
inline std:stream &Wrapper::cout() {
Lock lock(mutex);
return std::cout;
}
And then use it like this
Wrapper::cout() << "print something" << "print more" << std::endl;
How long does the scoped lock protect the access to std::cout? The
mutex is released within lock's destructor, which is called after the
return statement.
I tested it in an VM environment and it worked as far as I visually
checked the output. But does it work for sure?
Thanks for any insights!
Henryk