|
Boost Users : |
Subject: [Boost-users] Thread is not interrupted
From: Lloyd (lloyd_at_[hidden])
Date: 2010-01-06 08:23:13
Hi,
I am using boost::asio to create a server. When a new connection is
established (inside the asio read handle) a new thread (boost::thread) is
created. The thread object pointer is kept in a static vector. When the
next connection is established, the thread pointer available in the static
vector is read and interrupted. But the thread is not interrupted! The
thread is just an infinite loop, in which interruption is enabled. I have
wrttien the exception handler also. Not able to understand why this is not
working in this situation. Otherwise this works. To make this clear given
below are the code snippets...
//ASIO based read handler
void TCPConnection::HandleRead(const boost::system::error_code& Error)
{
TCPConnection::Threadvector[0]->interrupt(); //Threadvector is static
variable in the class, for easy reading written like this
boost::thread *th=new
boost::thread(boost::bind(&TCPConnection::ExecutionRoutine,shared_from_this(),Command));
TCPConnection::Threadvector.push_back(th);
}
//ExecutionRoutine looks like this
int TCPConnection::ExecutionRoutine(string Command)
{
try
{
while(1)
{
boost::this_thread::interruption_point();
}
}
catch(boost::thread_interrupted const&)
{
return 0;
}
return 0;
}
Please share some idea...
Thanks,
Lloyd
___________________
Happy New Year 2010
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net