[Qt-interest] SegFaults I cannot interpret

Arnold Krille arnold at arnoldarts.de
Tue Feb 24 20:37:37 CET 2009


Hi,

On Tuesday 24 February 2009 19:05:06 Andrea Franceschini wrote:
> Hello guys. Since I started developing this application I'm working
> on, I've had any sort of segfault, sometimes due to errors of mine --
> which have been fixed -- and sometimes due to conditions I cannot
> really grasp. I fear the problem may be somehow related to threading
> issues but it only appears sometimes while other times I can run
> flawlessly for a lot of time.

Sounds like race-conditions.

> Basically I have a QPainter derived class which has pointers to my
> datas and displays them on an appropriate QGLWidget. I tried to put
> mutexes everywhere (nontheless I tried with the QMutexLocker if by any
> chance I was missing something) but I found that it really affected
> the performance of the painter (while the logic still worked really
> well).

This shows that you are running different threads but these are very 
interleaved (which is a bad sign). QMutex makes this kind of save by assuring 
that only one threads can access the data. The fact that using mutexes removes 
the problems shows that your objects/threads are interleaved and the fact that 
using mutexes makes your painting really slow shows that they are to much 
interleaved. As far as I see it there are two solutions:
1) Remove the threads and execute all in the same thread. This is similar to 
using mutexes and might make your app slower.
2) Use one-way (ring-)buffers to send the data from the computing threads to 
the gui thread and back. This will make you loose "realtimeness" as now some 
data might be in the buffer and not get painted while it is already computed 
but this also lets all threads run at their needed speeds and de-interleaves 
the threads logic. (You can also use the Qt eventsystem with custom events, 
its fast enough, I have prove.)
But be aware that while really going multi-threaded might improve the painting 
performance, it opens a pandoras box of new problems. Not only with data 
access but also when creating new qobjects in the different threads and 
especially when creating qobjects in a thread due to external signals from 
outside that thread.

I struggled with the same problems when I made my work-but-opensource software 
multithreaded.

Have fun,

Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090224/23cea3cf/attachment.bin 


More information about the Qt-interest-old mailing list