[Qt-interest] Documentation on Mutex, Semaphore and Critical Section with Qt?
Sean Harmer
sean.harmer at maps-technology.com
Fri Jan 29 15:42:30 CET 2010
On Friday 29 January 2010 14:33:50 Matthias Pospiech wrote:
> Sean Harmer schrieb:
> >> My reinitialization it would look like this
> >>
> >> reinit()
> >> {
> >> lock.lockForWrite();
> >> if (device) {
> >> delete device;
> >> }
> >> device = new DeviceClass;
> >> lock.unlock();
> >> }
> >
> > Or even better use QWriteLocker locker( &mutex ) that way you are covered
> > at every possible exit point from your function including throwing
> > exceptions.
> >
> >> an in all accessing functions I would write:
> >>
> >> access()
> >> {
> >> lock.lockForRead();
> >> device->doSomething();
> >> lock.unlock();
> >> }
> >
> > Again, I would prefer to use QReadLocker.
>
> I do not see the difference between QReadWriteLock and a combination of
> QWriteLocker and QReadLocker,
> especially because in your approach it would be two different lockers
> which have nothing to do with each other?
I think you are missing the point. You use QReadLocker or QWriteLocker object
as a convenient way of locking a QReadWriteLock not instead of one.
Sean
More information about the Qt-interest-old
mailing list