I have read that both pthread_mutex_lock() and pthread_mutex_unlock() contain memory barriers.
And I also read that when you call a function, the function call itself act as a memory barrier.
So what is the point of including memory barriers in the functions pthread_mutex_lock() and pthread_mutex_unlock()?
I mean say that we have the following code:
a = 5;
b = 7;
pthread_mutex_lock(&lock);
i++;
pthread_mutex_unlock(&lock);
c = 10;
Whether pthread_mutex_lock() and pthread_mutex_unlock() contain memory barriers or not, the above code would still be executed the same.