I'm basically asking if I acquire a lock in one method and call a second method from that method, will the second one maintain exclusive memory access? Here is some example code. For reference, I'm coding in C using pthreads.
int count = 0;
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
method1() {
pthread_mutex_lock(&mutex);
count++;
method2();
pthread_mutex_unlock(&mutex);
}
method2() {
printf("count = %d\n", count);
}
So if thread A starts and calls method1 (acquiring the lock), would A's call of method2 within method1 still be memory locked since A still has the mutex lock? So no other threads could change count while A is still printing it?