摘要:
一个自动重置事件的对象,WaitForSingleObject在等待成功以后会把事件对象设置为未触发状态(马上调用ResetEvent()函数),而手动设置事件对象不会有这个副作用。#include <iostream>#include <process.h>#include <windows.h>#include <string>using std::cout;using std::endl;using std::string;const int num=10;int count;HANDLE ThreadEvent;unsigned __st 阅读全文
阅读排行榜
使用互斥量进行线程同步,与关键段和事件的区别
2012-12-15 01:56 by kennyMc, 2750 阅读, 收藏,
摘要:
1 #include <iostream> 2 #include <process.h> 3 #include <windows.h> 4 #include <string> 5 using std::cout; 6 using std::endl; 7 using std::string; 8 9 const int num=2;10 int count;11 unsigned __stdcall ThreadFun(void* par);12 13 int main()14 {15 count=0;16 HANDLE handles[num] 阅读全文
list.erase导致迭代器失效问题
2012-12-01 01:55 by kennyMc, 2449 阅读, 收藏,
摘要:
#include <iostream>#include <vector>#include <string>#include <typeinfo>#include <list>#include <deque>using std::cout;using std::endl;using std::vector;using std::string;using std::list;template<typename T>void fun(list<T> &l,const T &val){ li 阅读全文
WindowsAPI进行文件操作(同步模式)
2012-12-20 02:00 by kennyMc, 1763 阅读, 收藏,
摘要:
先用同步模式来进行文件的写入操作#include <iostream>#include<locale.h>#include <process.h>#include <windows.h>#include <string>#include <WCHAR.H>using std::cout;using std::endl;using std::string;int main(){ char *str="测试写入文件,HELLO KENNY"; cout<<"写入文件内容:"& 阅读全文
CRITICAL_SECTION的RecursionCount
2012-12-09 03:31 by kennyMc, 1540 阅读, 收藏,
摘要:
CRITICAL_SECTION结构的RecursionCount字段表示该关键段的拥有线程对此资源获得关键段次数,初为0。需要注意的地方:线程对同一个关键段n次EnterCriticalSection,那么需要相应的n次LeaveCriticalSection,不然RecursionCount不是0,其他线程就没法获得资源的访问权。#include <windows.h>#include <string>using std::cout;using std::endl;using std::string;CRITICAL_SECTION cs;int count;uns 阅读全文
浙公网安备 33010602011771号