[Qt-interest] Documentation on Mutex, Semaphore and Critical Section with Qt?

Matthias Pospiech matthias.pospiech at gmx.de
Fri Jan 29 11:05:34 CET 2010


Sean Harmer schrieb:
> Hi,
>
> On Friday 29 January 2010 09:42:52 Matthias Pospiech wrote:
>   
>> I am looking for general introduction and documentation of Mutex,
>> Semaphore, Critical Section and such.
>> (btw I could not see any difference between mutexes and critical
>> sections from what I found on the web).
>> Best would be if it would also describe the Qt-way of doing things if Qt
>> offers something in that case.
>>
>>     
> Take a look at these and the links contained therein:
>
> http://doc.trolltech.com/4.6/threads.html
> http://doc.trolltech.com/4.6/examples-threadandconcurrent.html
>
> The examples will give you a good feel for how to use the thread 
> synchronization classes in practice.
>   
 From all I can understand there is that  QMutexLocker is a nice tool, 
but has nothing
to do with locking several functions at once. It only works for a single 
function.
And that is not my problem.

For example I want to reinitialize a class member pointer, it could also 
be a global singleton.
I have to make sure that not a single class in acting on that pointer 
when I delete it. So I have to do something like
LockAllUses + WaitForAllUsesToFinish + reinitialize + ReleaseLockedUses

and that applicationwide whereevery the class containing the member is used.

I do not see where Mutex, Mutexlocker or Semaphores play any role in 
such a locking mechanism,
especially if it is in different threads. Here I would love to see more 
examples.
Previously I was sometimes told to use the wrong code design, but I need 
examples to design better.

Matthias



More information about the Qt-interest-old mailing list