[Qt-interest] efficient Wait for Thread finished?
Matthias Pospiech
matthias.pospiech at gmx.de
Tue Jan 20 21:06:53 CET 2009
Arnold Krille schrieb:
> 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). :-)
>
>
I have never worked with thread locking and although have read the
QMutex Doc page multiple times am not sure
if I got it right.
If I have inside a function this here:
QMutex mutex;
QMutexLocker locker(&mutex);
the any other function will not be affected because locking only happens
if in other functions the code execution comes along a
mutex.lock() which finds out that excatly this is already locked and
waits until this is unlocked. In the case of above locking will
then never happen because the mutex object is unknown outside of the
function.
If I put the
QMutex mutex;
in the class definition, then I use the same mutex everywhere in all
functions and locking is possible, but still any function not having a
mutex.lock() will still be executed.
Contrary to this, what I had been thinking first was that if I have any
mutex in a thread derived class that would block any attempt to access
members or functions in the class and cause a wait for the class to be
unlocked.
Please correct me if I am wrong.
More information about the Qt-interest-old
mailing list