使用ZThread的执行器 Executor 可以减少编码的工作量
执行器在客户和任务的执行之间提供了一个间接层
客户不再直接执行任务
而是由一个中间的对象来执行该任务这里要改个名字 要不然会重名
出现函数未定义
//: c11:ThreadedExecutor1.cpp
// From "Thinking in C++, Volume 2", by Bruce Eckel & Chuck Allison.
// (c) 1995-2004 MindView, Inc. All Rights Reserved.
// See source code use permissions stated in the file 'License.txt',
// distributed with the code package available at www.MindView.net.
//{L} ZThread
#include <iostream>
#include "zthread/ThreadedExecutor.h"
#include "LiftOff.h"
using namespace ZThread;
using namespace std;
int main() {
try {
ThreadedExecutor executor;
for(int i = 0; i < 5; i++)
executor.execute(new LiftOff(10, i));
} catch(Synchronization_Exception& e) {
cerr << e.what() << endl;
}
getchar();
} ///:~
输出
ThreadQueue created
User thread created.
Reference thread created.
1 reference-thread added.
pollPendingThreads()
1 user-thread added.
Thread starting...
User thread created.
0pollPendingThreads()
:1 user-thread added.
9Thread starting...
User thread created.
1
:90
:18:
8pollPendingThreads()
1 user-thread added.
10User thread created.
::77
10Thread starting...
:6
1pollPendingThreads()
1 user-thread added.
2Thread starting...
:36:
9:
5User thread created.
0:2pollPendingThreads()
1 user-thread added.
5
0::49Thread starting...
0::348
3:18
:4:
9
3:27:
7
1:03
4::83
:6
4:17:22
:6
2:25
42:4
1::106
4:5
2:1:03::51
4:
43
0:
0
Liftoff!
4:23
3:44:
Liftoff!