1#include "../Mutex.h"
2#include "../Thread.h"
3#include <vector>
4#include <stdio.h>
5
6using namespace muduo;
7
8class Foo
9{
10 public:
11  void doit() const;
12};
13
14MutexLock mutex;
15std::vector<Foo> foos;
16
17void post(const Foo& f)
18{
19  MutexLockGuard lock(mutex);
20  foos.push_back(f);
21}
22
23void traverse()
24{
25  MutexLockGuard lock(mutex);
26  for (std::vector<Foo>::const_iterator it = foos.begin();
27      it != foos.end(); ++it)
28  {
29    it->doit();
30  }
31}
32
33void Foo::doit() const
34{
35  Foo f;
36  post(f);
37}
38
39int main()
40{
41  Foo f;
42  post(f);
43  traverse();
44}
45
46