pthread_mutex_t 变量不建议做复制操作

参考:http://stackoverflow.com/questions/6310746/initializing-pthread-mutexes


下面的操作通常是不建议的:

static pthread_mutex_t m0 = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t m1 = m0;
因为,这样做过后,m1 和 m0 实际上是两个不同的 mutex,相互不相干,而这通常不是我们想要的结果。

同时,函数返回 pthread_mutext_t 类型值也是不建议的。


这里提到

Standard does not allow to copy mutexes by value or return them by value
即,不建议通过传值的方式拷贝 pthread_mutex_t,也不建议用传值的方式返回 pthread_mutex_t 类型

同时也有提到

The closest relative of pthread_mutex, WIN32 CriticalSection, is absolutely not copyable and not returnable by value
即,Windows下的 pthread_mutex_t 的等同物,CriticalSection,是绝对不可以 通过传值的方式拷贝 或 用传值的方式返回 的。




你可能感兴趣的:(pthread_mutex_t 变量不建议做复制操作)