1#include "../ThreadPool.h"
2#include "../CountDownLatch.h"
3
4#include <boost/bind.hpp>
5#include <stdio.h>
6
7void print()
8{
9  printf("tid=%d\n", muduo::CurrentThread::tid());
10}
11
12void printString(const std::string& str)
13{
14  printf("tid=%d, str=%s\n", muduo::CurrentThread::tid(), str.c_str());
15}
16
17int main()
18{
19  muduo::ThreadPool pool("MainThreadPool");
20  pool.start(5);
21
22  pool.run(print);
23  pool.run(print);
24  for (int i = 0; i < 100; ++i)
25  {
26    char buf[32];
27    snprintf(buf, sizeof buf, "task %d", i);
28    pool.run(boost::bind(printString, std::string(buf)));
29  }
30
31  muduo::CountDownLatch latch(1);
32  pool.run(boost::bind(&muduo::CountDownLatch::countDown, &latch));
33  latch.wait();
34  pool.stop();
35}
36
37