12d3b4de6SShuo Chen#include "../Mutex.h" 22d3b4de6SShuo Chen#include "../Thread.h" 32d3b4de6SShuo Chen#include <vector> 42d3b4de6SShuo Chen#include <stdio.h> 52d3b4de6SShuo Chen 62d3b4de6SShuo Chenusing namespace muduo; 72d3b4de6SShuo Chen 82d3b4de6SShuo Chenclass Foo 92d3b4de6SShuo Chen{ 102d3b4de6SShuo Chen public: 112d3b4de6SShuo Chen void doit() const; 122d3b4de6SShuo Chen}; 132d3b4de6SShuo Chen 142d3b4de6SShuo ChenMutexLock mutex; 15dc38cf72SShuo Chenstd::vector<Foo> foos; 162d3b4de6SShuo Chen 172d3b4de6SShuo Chenvoid post(const Foo& f) 182d3b4de6SShuo Chen{ 192d3b4de6SShuo Chen MutexLockGuard lock(mutex); 202d3b4de6SShuo Chen foos.push_back(f); 212d3b4de6SShuo Chen} 222d3b4de6SShuo Chen 232d3b4de6SShuo Chenvoid traverse() 242d3b4de6SShuo Chen{ 252d3b4de6SShuo Chen MutexLockGuard lock(mutex); 262d3b4de6SShuo Chen for (std::vector<Foo>::const_iterator it = foos.begin(); 272d3b4de6SShuo Chen it != foos.end(); ++it) 282d3b4de6SShuo Chen { 292d3b4de6SShuo Chen it->doit(); 302d3b4de6SShuo Chen } 312d3b4de6SShuo Chen} 322d3b4de6SShuo Chen 332d3b4de6SShuo Chenvoid Foo::doit() const 342d3b4de6SShuo Chen{ 352d3b4de6SShuo Chen Foo f; 362d3b4de6SShuo Chen post(f); 372d3b4de6SShuo Chen} 382d3b4de6SShuo Chen 392d3b4de6SShuo Chenint main() 402d3b4de6SShuo Chen{ 412d3b4de6SShuo Chen Foo f; 422d3b4de6SShuo Chen post(f); 432d3b4de6SShuo Chen traverse(); 442d3b4de6SShuo Chen} 452d3b4de6SShuo Chen 46