📄 wartestthreadpool.cpp
字号:
#include "stdafx.h"#include "WarThreadPool.h"#include "WarThreadPoolTask.h"#include "WarThreadForPool.h"#include <iostream>#include "WarLog.h"#include "WarLogIOStreamHandler.h"using namespace std;class MyTask : public WarThreadPoolTask{ enum RequestTypesE { /// Overrides declare their own request types REQUEST_TEST = REQUEST_NOOP + 1 }; std::string GetTypeName() const { return "REQUEST_TEST"; } protected: virtual void OnProcessing(WarThreadForPool * pThread) { WarLog log(WARLOG_INFO, "MyTask::OnProcessing()"); log << "Thread " << (unsigned)pThread->GetThreadId() << " Processing task " << (unsigned)GetTaskId() << war_endl; if (!(GetTaskId() % 5)) WarTime::Sleep(GetTaskId() * 10); }};void TestWarThreadPool(){#define MAX_TESTS 150 cout << "Testing WarThreadPool" << endl; WarLogEngine log_engine; log_engine.InstallHandler(new WarLogIoStreamHandler(cout, "cout")); log_engine.EnableEvent("cout", WARLOG_THREADS); WarLog log(WARLOG_INFO, "TestWarThreadPool()"); WarThreadPool pool; pool.Create(3, 10); for(int i = 0; i < MAX_TESTS; i++) { pool.PushTask(new MyTask); } log << "Done pushing tasks. Waiting for delayed destruction..." << war_endl;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -