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