摘要: 1:多线程所调用的成员方法定义为static。2:互斥锁(pthread_mutex_t)定义在cpp文件的开头,并且也定义为static。3:pthread_mutex_init方法尽量在最早的时候进行调用初始化(绝对不要在初始化之后立即开始新线程,否则pthread_mutex_lock很可能会返回22的错误,因为此时互斥量还没有初始化完成)。4:pthread_mutex_destroy方法尽量在最晚的匹配的时候调用(比如构造析构——配对)。代码:头文件public: pthread_t tid1; pthread_t tid2; static void* anothe... 阅读全文
posted @ 2013-06-21 19:54 leonbao 阅读(3132) 评论(0) 推荐(0) 编辑