-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (45 loc) · 1.09 KB
/
main.cpp
File metadata and controls
49 lines (45 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <iostream>
#include "threadpool/ThreadPool.h"
using namespace std;
class MyTask1:public Task{
public:
MyTask1(string name,int pri):Task(name){
setPriority(pri);
}
void run(){
printf("hello,this is MyTask1\n");
sleep(2);
}
};
void *printStr(void * str){
printf("%s\n",str);
}
int main(){
ThreadPool *pool=new ThreadPool(10);
// for(int i=0;i<2;i++){
// MyTask1 *task1=new MyTask1("mytask *",i+1);
// pool->addTask(task1);
// }
MyTask1 *task1=new MyTask1("mytask1",4);
pool->addTask(task1);
MyTask1 *task2=new MyTask1("mytask2",3);
pool->addTask(task2);
MyTask1 *task3=new MyTask1("mytask3",1);
pool->addTask(task3);
MyTask1 *task4=new MyTask1("mytask4",5);
pool->addTask(task4);
cout<<"pool size "<<pool->getPoolSize()<<endl;
sleep(1);
pool->delThread(1);
MyTask1 *task5=new MyTask1("mytask5",6);
pool->addTask(task5);
CbTask *task6=new CbTask("mytask6",1);
char *str="你好";
task6->setCallBack(printStr,static_cast<void*>(str));
pool->addTask(task6);
cout<<"pool size "<<pool->getPoolSize()<<endl;
sleep(3);
// pool->poolDestroy();
pool->~ThreadPool();
return 0;
}