test5.cc revision 40161064
140161064SShuo Chen#include "EventLoop.h"
240161064SShuo Chen#include <stdio.h>
340161064SShuo Chen
440161064SShuo Chenmuduo::EventLoop* g_loop;
540161064SShuo Chenint g_flag = 0;
640161064SShuo Chen
740161064SShuo Chenvoid run4()
840161064SShuo Chen{
940161064SShuo Chen  printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag);
1040161064SShuo Chen  g_loop->quit();
1140161064SShuo Chen}
1240161064SShuo Chen
1340161064SShuo Chenvoid run3()
1440161064SShuo Chen{
1540161064SShuo Chen  printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag);
1640161064SShuo Chen  g_loop->runAfter(3, run4);
1740161064SShuo Chen  g_flag = 3;
1840161064SShuo Chen}
1940161064SShuo Chen
2040161064SShuo Chenvoid run2()
2140161064SShuo Chen{
2240161064SShuo Chen  printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag);
2340161064SShuo Chen  g_loop->queueInLoop(run3);
2440161064SShuo Chen}
2540161064SShuo Chen
2640161064SShuo Chenvoid run1()
2740161064SShuo Chen{
2840161064SShuo Chen  g_flag = 1;
2940161064SShuo Chen  printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag);
3040161064SShuo Chen  g_loop->runInLoop(run2);
3140161064SShuo Chen  g_flag = 2;
3240161064SShuo Chen}
3340161064SShuo Chen
3440161064SShuo Chenint main()
3540161064SShuo Chen{
3640161064SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
3740161064SShuo Chen
3840161064SShuo Chen  muduo::EventLoop loop;
3940161064SShuo Chen  g_loop = &loop;
4040161064SShuo Chen
4140161064SShuo Chen  loop.runAfter(2, run1);
4240161064SShuo Chen  loop.loop();
4340161064SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
4440161064SShuo Chen}
45