Boost logo

Boost Users :

Subject: Re: [Boost-users] [Thread] Timed join returning true before thread terminated
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2012-03-15 14:41:59

Le 15/03/12 18:25, Anthony Williams a écrit :
> On 15/03/12 16:47, John Rocha wrote:
>> First I want to thank you for helping with this. How did you come to
>> this
>> answer so quickly? Is this a technique or tool that I can learn, or was
>> this
>> wisdom from having worked with your library for so long?
> I tried it out, saw the problem manifest, trapped it in gdb, and
> examined the code. I guess it's just experience.
>> Main
>> Uses SQ.shutdown() to shutdown the SQ thread it
>> sets the SQ.m_shutdown flag
>> sends the SQ thread a boost thread interrupt
>> joins on the thread
>> SQ Thread
>> This thread is running under it's thread_main() and __happens__ to be in
>> the is_shutdown() method, after it checked the interruption_point() but
>> BEFORE it checks the m_shutdown() logic. SQ.m_shudown was just
>> changed to
>> true, so is_shutdown() sees that and throws a boost::thread_interrupted
>> exception. However, it should also be noted that the boost thread
>> data has
>> its internal interrupt requested flag set too.
>> Now SQ Thread, "throws" out of thread_main() is caught by the base
>> classes
>> operator() method and enters the SQ.thread_shutdown method.
>> SQ.thread_shutdown needs to shut down it's lookup child thread. So it
>> invokes the LU.shutdown method.
>> The LU.shutdown method is just like above:
>> sets the LU.m_shutdown flag
>> sends the LU thread a boost thread interrupt
>> joins on the LU thread
>> However, join() is an interruption point, and I haven't "cleared the
>> interrupt" for the boost thread yet. Therefore, when the SQ thread
>> invokes
>> join(), it checks if there are any outstanding interrupts it needs to
>> honor. There are, so it throws another thread interrupted exception,
>> which
>> exits the join(), and I don't catch; therefore the SQ thread exits
>> prematurely due to my faulty logic.
> Yes, that matches my understanding.

does this means that there are some restrictions on the code that can be
executed on the boost::thread_interrupted catch handler or some
guidelines that s/he must follow?
Is it legal that the user throws itself a boost::thread_interrupted
exception? Is there a way to clear the interrupted flag so that the
join() is not interrupted on the boost::thread_interrupted catch handler?

What was wrong with the user code that made the library crash? Which
precondition of the library was violated? Maybe some assertions help so
that the error is identified as soon as possible.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at