1#include "../Thread.h"
2
3#include <string>
4#include <boost/bind.hpp>
5#include <stdio.h>
6
7void threadFunc()
8{
9  printf("tid=%d\n", muduo::CurrentThread::tid());
10}
11
12void threadFunc2(int x)
13{
14  printf("tid=%d, x=%d\n", muduo::CurrentThread::tid(), x);
15}
16
17void threadFunc3()
18{
19  printf("tid=%d\n", muduo::CurrentThread::tid());
20  sleep(1);
21}
22
23class Foo
24{
25 public:
26  explicit Foo(double x)
27    : x_(x)
28  {
29  }
30
31  void memberFunc()
32  {
33    printf("tid=%d, Foo::x_=%f\n", muduo::CurrentThread::tid(), x_);
34  }
35
36  void memberFunc2(const std::string& text)
37  {
38    printf("tid=%d, Foo::x_=%f, text=%s\n", muduo::CurrentThread::tid(), x_, text.c_str());
39  }
40
41 private:
42  double x_;
43};
44
45int main()
46{
47  printf("pid=%d, tid=%d\n", ::getpid(), muduo::CurrentThread::tid());
48
49  muduo::Thread t1(threadFunc);
50  t1.start();
51  t1.join();
52
53  muduo::Thread t2(boost::bind(threadFunc2, 42),
54                   "thread for free function with argument");
55  t2.start();
56  t2.join();
57
58  Foo foo(87.53);
59  muduo::Thread t3(boost::bind(&Foo::memberFunc, &foo),
60                   "thread for member function without argument");
61  t3.start();
62  t3.join();
63
64  muduo::Thread t4(boost::bind(&Foo::memberFunc2, boost::ref(foo), std::string("Shuo Chen")));
65  t4.start();
66  t4.join();
67
68  {
69    muduo::Thread t5(threadFunc3);
70    t5.start();
71  }
72  sleep(2);
73  printf("number of created threads %d\n", muduo::Thread::numCreated());
74}
75