12a18e699SShuo Chen#include "EventLoop.h"
22a18e699SShuo Chen#include <stdio.h>
32a18e699SShuo Chen
42a18e699SShuo Chenmuduo::EventLoop* g_loop;
52a18e699SShuo Chenint g_flag = 0;
62a18e699SShuo Chen
72a18e699SShuo Chenvoid run4()
82a18e699SShuo Chen{
92a18e699SShuo Chen  printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag);
102a18e699SShuo Chen  g_loop->quit();
112a18e699SShuo Chen}
122a18e699SShuo Chen
132a18e699SShuo Chenvoid run3()
142a18e699SShuo Chen{
152a18e699SShuo Chen  printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag);
162a18e699SShuo Chen  g_loop->runAfter(3, run4);
172a18e699SShuo Chen  g_flag = 3;
182a18e699SShuo Chen}
192a18e699SShuo Chen
202a18e699SShuo Chenvoid run2()
212a18e699SShuo Chen{
222a18e699SShuo Chen  printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag);
232a18e699SShuo Chen  g_loop->queueInLoop(run3);
242a18e699SShuo Chen}
252a18e699SShuo Chen
262a18e699SShuo Chenvoid run1()
272a18e699SShuo Chen{
282a18e699SShuo Chen  g_flag = 1;
292a18e699SShuo Chen  printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag);
302a18e699SShuo Chen  g_loop->runInLoop(run2);
312a18e699SShuo Chen  g_flag = 2;
322a18e699SShuo Chen}
332a18e699SShuo Chen
342a18e699SShuo Chenint main()
352a18e699SShuo Chen{
362a18e699SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
372a18e699SShuo Chen
382a18e699SShuo Chen  muduo::EventLoop loop;
392a18e699SShuo Chen  g_loop = &loop;
402a18e699SShuo Chen
412a18e699SShuo Chen  loop.runAfter(2, run1);
422a18e699SShuo Chen  loop.loop();
432a18e699SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
442a18e699SShuo Chen}
45