I am curious how does a mutex know what data to protect and what data not to protect. I've been using mutexes (mutices?) in Qt, and a QMutex
does not specify any particular members to be locked.
One idea that comes to my head is that the mutex doesn't lock any resource but a routine which works on a resource, and in order for that routine to work the mutex must be unlocked. But that would mean that if I can acquire a pointer to that resource, I can still modify it in another thread that doesn't go through the lockable routine, which would mean it is actually impossible to fully protect an area in memory, it can only be protected if it is only accessible through a single lockable routine. Is that correct?