[Qt-interest] efficient Wait for Thread finished?
Arnold Krille
arnold at arnoldarts.de
Tue Jan 20 11:41:51 CET 2009
On Tuesday 20 January 2009 11:00:08 Matthias Pospiech wrote:
> I have a QThread which saves my data. If my simulation is faster than
> the data was saved, I have to delay the simulation.
> Currently that looks like the following:
> #ifndef _DELAY_H
> #define _DELAY_H
> #include <QtCore/QTime>
> inline void delay(long ms) // Zeit im ms
> {
> QTime time;
> time.start();
> while (time.elapsed()<ms);
> }
> #endif
> void SaveDataThread::reset()
> {
> // only reset if not running anymore
> while (isRunning()) {
> delay(200);
> }
> ...
> }
> Is this method ok? Or is the delay comsumming CPU and therefore
> additionally blocking the Thread?
> How should it look like?
How is your simulation transfering the data to the save-thread? Via Qt-ways?
Then why not control access to the save-thread with a mutex and use the
automatic wait of QMutex::lock() / QMutexLocker()?
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/20090120/e5b2c90b/attachment.bin
More information about the Qt-interest-old
mailing list