2014年10月6日
摘要: 在之前,我们写过类似的stacktemplate >class Stack{public: void push(const T &); void pop(); T top() const; bool empty() const;private: Alloc cont_... 阅读全文
posted @ 2014-10-06 20:46 inevermore 阅读(1942) 评论(0) 推荐(1) 编辑
摘要: C++11提供了thread,但是过于复杂,我们还是倾向于在项目中编写自己的Thread。 Posix Thread的使用这里不再赘述。 重点是这个函数: #include int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_... 阅读全文
posted @ 2014-10-06 18:55 inevermore 阅读(1617) 评论(0) 推荐(0) 编辑
摘要: 条件变量主要用于实现线程之间的协作关系。 pthread_cond_t常用的操作有: int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr); int pthread_cond_signal(pthread_cond_t *cond); int pthread_cond_broadcast(pt... 阅读全文
posted @ 2014-10-06 16:37 inevermore 阅读(1386) 评论(2) 推荐(0) 编辑
摘要: 本文对Linux中的pthread_mutex_t做一个简易的封装。 互斥锁主要用于互斥,互斥是一种竞争关系,主要是某一个系统资源或一段代码,一次做多被一个线程访问。 条件变量主要用于同步,用于协调线程之间的关系,是一种合作关系。 Linux中互斥锁的用法很简单,最常用的是以下的几个函数: int pthread_mutex_init(pthread_mutex_t *mutex, ... 阅读全文
posted @ 2014-10-06 16:28 inevermore 阅读(1313) 评论(0) 推荐(1) 编辑