I have an application on windows that uses multiple threads, but when
ever I
cout << "Write Something" << endl;
the I/O stops working. I created a SafeCout class that should work but
does not.
class SafeCoutObj {
public:
stringstream Out;
SafeCoutObj & operator << (SafeCoutObj& (*pf)(SafeCoutObj&))
{ return pf (*this)}
SafeCoutObj & endl()
{
lock(Mutex);
printf("%s", Out.str().c_str());
Out.str()"");
unlock(Mutex);
return *this;
}
}
template <class Type>
inline SafeCoutObj& operator << (SafeCoutObj& os, Type val)
{
os.Out << val;
return os;
}
inline SafeCoutObj& endl(SafeCoutObj& os)
{
os.endl();
return os;
}
Each thread has its own local copy of SafeCout it writes to.
When I run, everything starts out okay, but eventually, the endl
function puts out the same line twice, and everything dies.
Any thoughts? Is this a Codewarrior cout limitation or multi-thread
I/O problem?
Thanks