正确示例:
pthread_mutex_lock(&mutex1) variableA = 1; variableB = 2; pthread_mutex_unlock(&mutex1) pthread_mutex_lock(&mutex1) localA = variableA; /* variableA = 1 */ localB = variableB; /* variableA = 2 */ pthread_mutex_unlock(&mutex1)
错误示例:
pthread_mutex_lock(&mutex1) variableA = 1; pthread_mutex_unlock(&mutex1) variableB = 2; pthread_mutex_lock(&mutex1) localA = variableA; /* variableA = 1 */ localB = variableB; /* variableA = 2 */ pthread_mutex_unlock(&mutex1)
原文:http://www.cnblogs.com/licongyu/p/5061291.html