Win32 线程的创建&信号量临界资源&事件对象
2020-11-24 20:38
标签:win32 线程 背景: 写了个程序,主要实现的功能为主线程创建两个子线程,之后主线程进入等待事件的循环。子线程1对临界资源cnt的值减2并输出cnt的值。子线程2对cnt的值加1并输出cnt的值,且当cnt为50的时候触发事件对象hend_even,子进程2退出。主线程收到hend_even后杀死子线程1,之后进入scanf阻塞。。。 代码示例: thread A delete 2 of cnt = 98 参考:
http://www.cnblogs.com/1314NNNKKK/p/3386375.html
http://hi.baidu.com/kdlipm/item/005be8eb29d785e1fa42bae5 Win32 线程的创建&信号量临界资源&事件对象 标签:win32 线程 原文地址:http://blog.csdn.net/ordeder/article/details/24646899#include
运行结果:
thread B add 1 of cnt = 99
thread A delete 2 of cnt = 97
thread B add 1 of cnt = 98
thread A delete 2 of cnt = 96
thread B add 1 of cnt = 97
thread A delete 2 of cnt = 95
thread B add 1 of cnt = 96
thread A delete 2 of cnt = 94
thread B add 1 of cnt = 95
thread A delete 2 of cnt = 93
thread B add 1 of cnt = 94
thread A delete 2 of cnt = 92
thread B add 1 of cnt = 93
thread A delete 2 of cnt = 91
thread B add 1 of cnt = 92
thread A delete 2 of cnt = 90
thread B add 1 of cnt = 91
thread A delete 2 of cnt = 89
thread B add 1 of cnt = 90
thread A delete 2 of cnt = 88
thread B add 1 of cnt = 89
...
thread A delete 2 of cnt = 51
thread B add 1 of cnt = 52
thread A delete 2 of cnt = 50
thread B add 1 of cnt = 51
thread A delete 2 of cnt = 49
thread B add 1 of cnt = 50
proc B stop to sail ticket...
proc B stop to sail ticket...
back to main thread...
上一篇:java报表导出
文章标题:Win32 线程的创建&信号量临界资源&事件对象
文章链接:http://soscw.com/index.php/essay/22457.html