forked from shihyu/DesignPatternExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
41 lines (31 loc) · 673 Bytes
/
Copy pathmain.c
File metadata and controls
41 lines (31 loc) · 673 Bytes
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
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include "base.h"
#include "icommand.h"
#include "thread_pool.h"
typedef struct _Task {
union {
ICommand;
ICommand icommand;
};
} Task;
void Task_execute(ICommand* icommand)
{
printf("command, tid=%lu\n", pthread_self());
}
int main()
{
ThreadPool* threadPool = new(ThreadPool, 10);
Task task;
task.execute = Task_execute;
threadPool->start(threadPool);
int i;
for (i = 0; i < 20; ++i) {
threadPool->execute(threadPool, &task.icommand);
}
sleep(3);
threadPool->stop(threadPool);
delete(ThreadPool, threadPool);
return 0;
}