Hi Rush
I thank you very much! It works and now boost::interrupt is more clear to me.

Can I ask you and who might help me one more question if you have time? 
I hope is an easy one.

In a scenario where my thread is very CPU consuming , in your opinion which is the better 
way to create an interruption point? 

#1 using a call to boost::this_thread::interruption_point() 
#2 or using boost::this_thread::sleep( boost::posix_time::milliseconds( 0 ) )

Initially I thought the probably #1 might be better since seems created just to throw the boost::thread_interrupted without any extra overhead due to call to OS time posix libraries.

I gave a thought and I think that it might be better to chose the second one since giving sleep( 0 ) might help the
OS scheduler in switching to another thread blocked. I am running under Linux but I think that also in Windows might be the same. 

Do you think that this reasoning make sense ?
Beside my specific case is it more efficient to call boost::this_thread::interruption_point()?

Kind Regards
AFG

On Sun, Jun 13, 2010 at 9:07 PM, Rush Manbert <rush@manbert.com> wrote:

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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users