1c461658bSShuo Chen#include "EventLoop.h" 2c461658bSShuo Chen#include <stdio.h> 3c461658bSShuo Chen 49807252eSShuo Chenmuduo::EventLoop* g_loop; 59807252eSShuo Chenint g_flag = 0; 69807252eSShuo Chen 79807252eSShuo Chenvoid run4() 89807252eSShuo Chen{ 99807252eSShuo Chen printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag); 109807252eSShuo Chen g_loop->quit(); 119807252eSShuo Chen} 129807252eSShuo Chen 139807252eSShuo Chenvoid run3() 149807252eSShuo Chen{ 159807252eSShuo Chen printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag); 169807252eSShuo Chen g_loop->runAfter(3, run4); 179807252eSShuo Chen g_flag = 3; 189807252eSShuo Chen} 199807252eSShuo Chen 209807252eSShuo Chenvoid run2() 219807252eSShuo Chen{ 229807252eSShuo Chen printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag); 239807252eSShuo Chen g_loop->queueInLoop(run3); 249807252eSShuo Chen} 259807252eSShuo Chen 269807252eSShuo Chenvoid run1() 27c461658bSShuo Chen{ 289807252eSShuo Chen g_flag = 1; 299807252eSShuo Chen printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag); 309807252eSShuo Chen g_loop->runInLoop(run2); 319807252eSShuo Chen g_flag = 2; 32c461658bSShuo Chen} 33c461658bSShuo Chen 34c461658bSShuo Chenint main() 35c461658bSShuo Chen{ 369807252eSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 37c461658bSShuo Chen 389807252eSShuo Chen muduo::EventLoop loop; 399807252eSShuo Chen g_loop = &loop; 40c461658bSShuo Chen 419807252eSShuo Chen loop.runAfter(2, run1); 429807252eSShuo Chen loop.loop(); 439807252eSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 44c461658bSShuo Chen} 45