資源簡介
用C++編寫的線程池實現源代碼,經過本人調試通過,能夠模擬簡單的線程池過程,代碼有較詳細注釋,易于理解。

代碼片段和文件信息
#include?“Thread.h“???
#include???
#include?
?
class?CMyTask:?public?CTask??
{??
public:??
CMyTask(){}??
??
inline?int?Run()??
{??
printf(“%s/n“?(char*)this->m_ptrData);??
????Sleep(10);??
return?0;??
}??
};????
int?main()??
{??
????CMyTask?taskObj;????????
char?szTmp[]?=?“this?is?the?first?thread?running\n“;??
taskObj.SetData((void*)szTmp);??
????CThreadPool?threadPool(10);??
????for(int?i?=?0;?i?20;?i++)??
{??
threadPool.AddTask(&taskObj);??
}????
while(1)??
{??
printf(“there?are?still?%d?tasks?need?to?handle/n“?threadPool.getTaskSize());??
if?(threadPool.getTaskSize()?==?0)??
{??
if?(threadPool.StopAll()?==?-1)??
{?????
printf(“Now?I?will?exit?from?main\n“);??
exit(0);??
}??
}??
Sleep(2);??
???}??
return?0;??
}??
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????33215??2013-11-28?15:05??ThreadPool\Debug\main.obj
?????文件?????175456??2013-11-28?14:56??ThreadPool\Debug\Thread.obj
?????文件?????540761??2013-11-28?15:05??ThreadPool\Debug\ThreadPool.exe
?????文件?????807304??2013-11-28?15:05??ThreadPool\Debug\ThreadPool.ilk
?????文件????2407332??2013-11-28?14:57??ThreadPool\Debug\ThreadPool.pch
?????文件????1336320??2013-11-28?15:05??ThreadPool\Debug\ThreadPool.pdb
?????文件?????205824??2013-11-28?15:26??ThreadPool\Debug\vc60.idb
?????文件?????159744??2013-11-28?15:05??ThreadPool\Debug\vc60.pdb
?????文件????????846??2013-11-28?15:41??ThreadPool\main.cpp
?????文件??????16116??2013-11-28?11:25??ThreadPool\pthread.h
?????文件?????119888??2012-05-27?00:00??ThreadPool\pthreadGC2.dll
?????文件?????121953??2012-05-27?00:00??ThreadPool\pthreadGCE2.dll
?????文件??????55808??2012-05-27?00:00??ThreadPool\pthreadVC2.dll
?????文件??????61952??2012-05-27?00:00??ThreadPool\pthreadVCE2.dll
?????文件??????57344??2012-05-27?00:00??ThreadPool\pthreadVSE2.dll
?????文件???????2791??2013-11-28?14:55??ThreadPool\Thread.cpp
?????文件???????1534??2013-11-28?14:55??ThreadPool\Thread.h
?????文件???????4589??2013-11-28?15:41??ThreadPool\ThreadPool.dsp
?????文件????????545??2013-11-28?15:41??ThreadPool\ThreadPool.dsw
?????文件??????41984??2013-11-28?15:41??ThreadPool\ThreadPool.ncb
?????文件??????48640??2013-11-28?15:41??ThreadPool\ThreadPool.opt
?????文件??????14328??2012-05-27?00:00??ThreadPool\thread頭文件\ANNOUNCE
?????文件???????6498??2012-05-27?00:00??ThreadPool\thread頭文件\BUGS
?????文件?????200896??2012-05-27?00:00??ThreadPool\thread頭文件\ChangeLog
?????文件???????5624??2012-05-27?00:00??ThreadPool\thread頭文件\CONTRIBUTORS
?????文件???????5939??2012-05-27?00:00??ThreadPool\thread頭文件\COPYING
?????文件??????26934??2012-05-27?00:00??ThreadPool\thread頭文件\COPYING.LIB
?????文件?????????98??2012-05-27?00:00??ThreadPool\thread頭文件\dll\x64\md5.sum
?????文件?????185976??2012-05-27?00:00??ThreadPool\thread頭文件\dll\x64\pthreadGC2.dll
?????文件??????82944??2012-05-27?00:00??ThreadPool\thread頭文件\dll\x64\pthreadVC2.dll
............此處省略49個文件信息
- 上一篇:MFC做的計算三角形面積
- 下一篇:C++編寫Genesis200自動化
評論
共有 條評論