摘要: 先上代码,主要是线程类"CLThread": 头文件: View Code #ifndef CLTHREAD_H#define CLTHREAD_H#include #include "CLExecutive.h"#include "CLStatus.h"#include "CLEv... 阅读全文
posted @ 2011-10-22 21:26 lq0729 阅读(902) 评论(0) 推荐(0) 编辑
摘要: POSIX.1说明:pthread_cond_broadcast等函数的调用无需考虑调用线程是否拥有锁,并建议在在lock和unlock以外的区域调用。为什么? §假设系统中有线程 1和线程 2:线程 1获取 mutex,在进行数据处理的时候,线程 ... 阅读全文
posted @ 2011-10-22 15:19 lq0729 阅读(1250) 评论(0) 推荐(0) 编辑
摘要: View Code #include #include #include "CLThread.h"#include "CLExecutiveFunctionProvider.h"#include "CLMutex.h"#include "CLCriticalSection.h"#in... 阅读全文
posted @ 2011-10-22 12:34 lq0729 阅读(735) 评论(0) 推荐(0) 编辑
摘要: 1. 首先pthread_cond_wait 的定义是这样的 The pthread_cond_wait() and pthread_cond_timedwait() functions are used to block on a condition variable. They are ca... 阅读全文
posted @ 2011-10-22 11:48 lq0729 阅读(1596) 评论(0) 推荐(0) 编辑
摘要: 测试(其余代码相同): View Code #include #include #include "CLThread.h"#include "CLExecutiveFunctionProvider.h"#include "CLMutex.h"#include "CLCriticalS... 阅读全文
posted @ 2011-10-21 22:49 lq0729 阅读(511) 评论(0) 推荐(0) 编辑
摘要: 本节在上一节的基础上,利用局部变量的构造和析构函数的特性,封装了对临界区的加锁和解锁操作,保证了程序(线程)在异常终止或中途退出的情况下也能正确解锁,从而不会出现死锁。 增加的临界区类"CLCriticalSection",其它源代码同上一节。 头文件: View Code #ifn... 阅读全文
posted @ 2011-10-21 20:21 lq0729 阅读(1591) 评论(0) 推荐(0) 编辑
摘要: 本节的源程序基于"Linux学习之线程封装四:基于接口的封装"一节。 增加了封装的互斥量类"CLMutex"(互斥量的创建封装进构造函数,销毁封装进析构函数,还结合CLLog类增加了错误处理)。 头文件: View Code #ifndef CLMutex_H#define CLMu... 阅读全文
posted @ 2011-10-21 18:00 lq0729 阅读(4903) 评论(1) 推荐(1) 编辑
摘要: 详见百度百科”互斥锁“ 阅读全文
posted @ 2011-10-21 12:36 lq0729 阅读(229) 评论(0) 推荐(0) 编辑
摘要: 在“Linux学习之线程封装五:基于接口的封装”的基础上,增加了协调器类“CLCoordinator”。 业务逻辑提供者类“CLCoordinator”,与“五”一样。 执行体类“CLExecutive”,将类的和构造函数的CLExecutiveFunctionProvider类型成员换成了CLCo... 阅读全文
posted @ 2011-10-21 12:17 lq0729 阅读(545) 评论(2) 推荐(0) 编辑
摘要: 三个方面:业务逻辑,执行体,协调器(装配前两者) View Code #include#include#include#include#include"CLStatus.h"#include"CLLog.h"using namespace std;class CMyFunction{... 阅读全文
posted @ 2011-10-20 22:47 lq0729 阅读(321) 评论(0) 推荐(0) 编辑