PDA

View Full Version : mutex pointer in QMutexLocker



anbu01
18th August 2015, 11:13
Hi,
Can we use a mutex pointer inside QMutexLocker.For example:-

MyClass.h


QMutex *m_mutexPtr;

MyClass.cpp


void myFunction() const
{
QMutexLocker locker(m_mutexPtr);
......
}

Is it right way to use like this because the editor shows locker as unused variable,this happens only when i use mutex variable as Pointer.So is it wrong.I have attached image showing the editor.

anda_skoa
18th August 2015, 13:23
QMutexLocker always works on a QMutex pointer.
And yes, in most cases it is not used after instantiation (RAII idiom (https://en.wikipedia.org/wiki/RAII)).

Cheers,
_

anbu01
18th August 2015, 14:18
@anda:
I understood that,but my doubt is why editor doesn't show anything(unused) if i use normal variable.

anda_skoa
18th August 2015, 15:11
No idea, the locker variable is still unused.
No point in wasting any time on that.

Cheers,
_