[Qt-interest] efficient Wait for Thread finished?
Arnold Krille
arnold at arnoldarts.de
Tue Jan 20 18:11:58 CET 2009
On Tuesday 20 January 2009 17:43:27 Matthias Pospiech wrote:
> So if I use
> void SaveDataThread::saveData()
> {
> QMutexLocker locker(&mutex);
> ...
> }
> how do I test in all the other member functions that the saveData is
> still running? I could not find any such function in Mutex or MutexLocker.
Well, your saveData should lock the mutex only short before accessing the
communication data-structure (and release the lock shortly afterwards).
And the other threads that want to access this data-structure lock the same
mutex shortly before. And when the mutex is already locked by another thread,
their lock()-function will block until the mutex is released. If you want the
non-blocking behaviour you should look at tryLock() but then you have to check
its return value whether you got the lock or not.
That is all described pretty well in the Qt docs, I got most of my multi-
thread knowledge from there (and from actually using it). :-)
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/20090120/0254f94f/attachment.bin
More information about the Qt-interest-old
mailing list