
SPY++查看 进程下
面的线程:

另一个线程函数:

定义一个指针变量:
在构造函数中初始化:

暂停线程:

线程继续:

定义布尔变量 记录 线程有没有在运行:
初始化该变量:


修改县城函数demoA:

对话框添加按钮,双击该按钮:
增加一个线程函数:
实现线程函数:
增加第2个按钮 掉用第二个线程函数:‘

按了第一个按钮立马按第二个按钮时 也就是当两个线程并发执行时就会出错:


以上是线程同步的四种方法,是MFC的C++类
定义指针:指向临界区对象:

在构造函数中 创建临界区对象
如下 用临界区对象调用lock()函数便可保护操作内容
第一个线程结束 了 第二个线程才成调用
//////////////////////////////////////////////////////////////////////////
法二使用互斥量对象进行线程同步:
定义指针指向互斥量对象:
创建互斥量对象:

CSingleLock为MFC中的类:

线程B一样:
///////////////////////////////////////////////////
法三 信号量:


其余不变:
线程B一样用信号量创建锁:
定义变量:


析构如下:


另一个进程也一样。