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:
  1. thread::run()
  2. {
  3. while(1)
  4. {
  5. if(someCondition)
  6. privateMember++;
  7. }
  8. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. thread::getPrivateMember()
  2. {
  3. return privateMember;
  4. }
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