Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Async break while ( std::getline( std::cin, str ) ) loop

32 views
Skip to first unread message

VladislavKurmaz

unread,
Dec 21, 2009, 10:29:00 AM12/21/09
to
Hi.

How can i legally break interactive input loop from another thread?

class CWorker
{
public:
/** */
void operator()()
{
//...
// !!! break main input loop here !!!
}
/** */
void processCommand( std::string& /*cmd*/ )
{
}
protected:
private:
};

int main(int /*argc*/, char* /*argv*/[] )
{
try
{
CWorker w;
boost::thread work_thread( boost::ref( w ) );
//
std::string str;
while ( std::getline( std::cin, str ) )
{
w.processCommand( str );
}
//
work_thread.join();
}
catch (std::exception& e)
{
std::cerr << "Exception: " << e.what() << "\n";
}
return 0;
}

0 new messages