
Untitled
By: a guest on
May 4th, 2012 | syntax:
None | size: 0.62 KB | hits: 13 | expires: Never
Synchronous reading from IOBuffer
void thread1_func(ostream& os)
{
sleep(10);
os << 12;
sleep(10);
os << "text";
sleep(10);
os << MyObject();
}
void thread2_func(istream& is)
{
int i = 0;
std::string str;
MyObject obj;
is >> 12; // waits until 12 is written
is >> str; // waits for "text"
is >> obj; // waits for MyObject
}
void main()
{
IOBuffer buf;
// create two threads:
thread1_func(ostream(buf));
thread2_func(istream(buf));
}
void main()
{
boost::asio::streambuf buf;
std::ostream os(&buf);
std::istream is(&buf);
//...
}