The question I am about to ask was actually asked in this thread: http://www.qtforum.org/article/32113...questions.html
But wasn't really properly answered...
Here is some code to explain the question:
Subclassed from QThread:
Qt Code:
thread::run() { while(1) { if(someCondition) privateMember++; } }To copy to clipboard, switch view to plain text mode
Qt Code:
thread::getPrivateMember() { return privateMember; }To copy to clipboard, switch view to plain text mode
Q: Is it necessary to protect privateMember with mutexes in the above case [as in a lock()/unlock() pair in run() and a QMutexLocker in getPrivateMember()] ?
OR, is privateMember automatically protected seeing as the "get" function is a member function of a QThread-derived class. In other words, run() and getPrivateMember() will never run at the same time and are thus protected?
Can someone shed some light on this?
Cheers
Bookmarks