[Qt-interest] SIGSEGV with single-line gdb backtrace
Bill King
bill.king at nokia.com
Mon Sep 28 06:01:40 CEST 2009
On 09/28/2009 12:09 PM, ext Josiah Bryan wrote:
>
>
> Alright, I narrowed it down using the good old-fashioned
> "comment-out-lines-until-it-stops-crashing" method - and narrowed it
> down to an obscure place in the destructor of my video decoder QThread:
> At one point, I free all the libav stuff allocated, and one of the lines
> does this:
>
> av_free(m_av_frame);
>
> Where m_av_frame was simply allocated earlier by "m_av_frame =
> avcodec_alloc_frame();"
>
> So, bottom line, somehow multithreading libavcodec et al is crashing a
> QThread. The odd thing is, I've got two other calls to av_free for other
> structures right above the free on m_av_frame - all are member variables
> of the thread, none should be accessed by any other thread. Access to
> the video frame is thru a mutex-locked buffer - the frame is converted
> from the video's internal format to an rgb frame, a QImage allocated and
> data copied into its bits(), and stuffed into the buffer with a mutex
> lock. Any other thread (GUI thread) that wants a frame uses the buffer,
> not even touching the decoder thread itself.
>
> How, then, is this rotten piece of code causing a race condition and a
> bloody SIGSEGV?
>
> (BTW, I'm trying to update valgrind now - recompiling now. All the above
> ranting was done based on source tracing. Any ideas from that? Or do I
> still need to dredge up valgrind?)
>
> Thanks,
> -josiah
>
>
>
>
>
Nothing really concrete :) Generally unless a library explicitly tells
you it's thread-safe, or re-entrant, then I avoid making the assumption
that it will be.
Is there a way you can set up a whole av lib session per thread? (ie, in
our database code, we state that a database connection is safe for the
thread it was contained in, but we don't make any guarantees outside of
that, so all accesses to that db via that connection need to occur
within that one thread. multiple connections allow access via multiple
threads).
If you can't do that then the worst case scenario, you may need to
critsect around all calls to the library :/, and yeah, that's a massive
bottleneck and really not the direction you want to be heading.
--
Bill King, Software Engineer
Qt Development Frameworks, Nokia Pty Ltd
Brisbane Office
More information about the Qt-interest-old
mailing list