Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Codewarrior Windows > cout and multip...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 240 of 318
Post > Topic >>

cout and multiple threads

by "SiamGod" <ed.woods@[EMAIL PROTECTED] > Jan 6, 2005 at 12:23 PM

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




 1 Posts in Topic:
cout and multiple threads
"SiamGod" <e  2005-01-06 12:23:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 12:47:17 CDT 2008.