1#include "EventLoop.h"
2#include <stdio.h>
3
4muduo::EventLoop* g_loop;
5int g_flag = 0;
6
7void run4()
8{
9  printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag);
10  g_loop->quit();
11}
12
13void run3()
14{
15  printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag);
16  g_loop->runAfter(3, run4);
17  g_flag = 3;
18}
19
20void run2()
21{
22  printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag);
23  g_loop->queueInLoop(run3);
24}
25
26void run1()
27{
28  g_flag = 1;
29  printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag);
30  g_loop->runInLoop(run2);
31  g_flag = 2;
32}
33
34int main()
35{
36  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
37
38  muduo::EventLoop loop;
39  g_loop = &loop;
40
41  loop.runAfter(2, run1);
42  loop.loop();
43  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
44}
45