19a1e991dSShuo Chen#include "EventLoop.h" 29a1e991dSShuo Chen#include <stdio.h> 39a1e991dSShuo Chen 49a1e991dSShuo Chenmuduo::EventLoop* g_loop; 59a1e991dSShuo Chenint g_flag = 0; 69a1e991dSShuo Chen 79a1e991dSShuo Chenvoid run4() 89a1e991dSShuo Chen{ 99a1e991dSShuo Chen printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag); 109a1e991dSShuo Chen g_loop->quit(); 119a1e991dSShuo Chen} 129a1e991dSShuo Chen 139a1e991dSShuo Chenvoid run3() 149a1e991dSShuo Chen{ 159a1e991dSShuo Chen printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag); 169a1e991dSShuo Chen g_loop->runAfter(3, run4); 179a1e991dSShuo Chen g_flag = 3; 189a1e991dSShuo Chen} 199a1e991dSShuo Chen 209a1e991dSShuo Chenvoid run2() 219a1e991dSShuo Chen{ 229a1e991dSShuo Chen printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag); 239a1e991dSShuo Chen g_loop->queueInLoop(run3); 249a1e991dSShuo Chen} 259a1e991dSShuo Chen 269a1e991dSShuo Chenvoid run1() 279a1e991dSShuo Chen{ 289a1e991dSShuo Chen g_flag = 1; 299a1e991dSShuo Chen printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag); 309a1e991dSShuo Chen g_loop->runInLoop(run2); 319a1e991dSShuo Chen g_flag = 2; 329a1e991dSShuo Chen} 339a1e991dSShuo Chen 349a1e991dSShuo Chenint main() 359a1e991dSShuo Chen{ 369a1e991dSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 379a1e991dSShuo Chen 389a1e991dSShuo Chen muduo::EventLoop loop; 399a1e991dSShuo Chen g_loop = &loop; 409a1e991dSShuo Chen 419a1e991dSShuo Chen loop.runAfter(2, run1); 429a1e991dSShuo Chen loop.loop(); 439a1e991dSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 449a1e991dSShuo Chen} 45