|
Boost Users : |
Subject: Re: [Boost-users] help with thread::interrupt
From: Rush Manbert (rush_at_[hidden])
Date: 2010-06-13 15:07:27
On Jun 13, 2010, at 11:43 AM, Conoscenza Silente wrote:
> Hi All
> I am playing with boost::thread and it is not clear how thread::interrupt actually works.
>
> If I understood clearly the thread will be interrupted the next time it enters one of the predefined interruption points; since thread::join is one interruption point, after I call tr.interrupt() I am expected that the thread will throw a boost::thread_interrupted exception once I call tr.join() right? .
>
I believe that if your thread had started a second thread and was waiting on thread::join() for the second level thread to finish, and if you called thread::interrupt on the first thread, then you would see the exception.
i.e.
void levelTwo (void)
{
while (true)
{
;
}
}
void levelOne (void)
{
try
{
boost::thread t2 (levelTwo);
t2.join();
}
catch (const boost::thread_interrupted& ex )
{
std::cout << "levelOne was interrupted" << std::endl;
}
}
int main( int argc, char** argv ){
boost::thread t1( levelOne );
boost::this_thread::sleep( boost::posix_time::seconds( 3 ) );
std::cout << "calisl to INTER." << std::endl; std::cout.flush();
t1.interrupt();
}
- Rush
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