Qt Code:
  1. private bool stopped;
  2. ......
  3.  
  4. void Thread::run()
  5. {
  6. forever {
  7. mutex.lock();
  8. if (stopped) {
  9. stopped = false;
  10. mutex.unlock();
  11. break;
  12. }
  13. mutex.unlock();
  14. cerr << qPrintable(messageStr);
  15. }
  16. cerr << endl;
  17. }
To copy to clipboard, switch view to plain text mode 

I don't understand why do we have to use mutex to lock the memeber of this class?
when you create the object of this class and call start() to start the thread, this object is unique, there is only one "stopped" !! why do we have to lock it before to write to it?