12745a763SShuo Chen#include "EventLoop.h" 22745a763SShuo Chen#include <stdio.h> 32745a763SShuo Chen 4eab5e07bSShuo Chenmuduo::EventLoop* g_loop; 5eab5e07bSShuo Chenint g_flag = 0; 6eab5e07bSShuo Chen 7eab5e07bSShuo Chenvoid run4() 8eab5e07bSShuo Chen{ 9eab5e07bSShuo Chen printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag); 10eab5e07bSShuo Chen g_loop->quit(); 11eab5e07bSShuo Chen} 12eab5e07bSShuo Chen 13eab5e07bSShuo Chenvoid run3() 14eab5e07bSShuo Chen{ 15eab5e07bSShuo Chen printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag); 16eab5e07bSShuo Chen g_loop->runAfter(3, run4); 17eab5e07bSShuo Chen g_flag = 3; 18eab5e07bSShuo Chen} 19eab5e07bSShuo Chen 20eab5e07bSShuo Chenvoid run2() 21eab5e07bSShuo Chen{ 22eab5e07bSShuo Chen printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag); 23eab5e07bSShuo Chen g_loop->queueInLoop(run3); 24eab5e07bSShuo Chen} 25eab5e07bSShuo Chen 26eab5e07bSShuo Chenvoid run1() 272745a763SShuo Chen{ 28eab5e07bSShuo Chen g_flag = 1; 29eab5e07bSShuo Chen printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag); 30eab5e07bSShuo Chen g_loop->runInLoop(run2); 31eab5e07bSShuo Chen g_flag = 2; 322745a763SShuo Chen} 332745a763SShuo Chen 342745a763SShuo Chenint main() 352745a763SShuo Chen{ 36eab5e07bSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 372745a763SShuo Chen 38eab5e07bSShuo Chen muduo::EventLoop loop; 39eab5e07bSShuo Chen g_loop = &loop; 402745a763SShuo Chen 41eab5e07bSShuo Chen loop.runAfter(2, run1); 42eab5e07bSShuo Chen loop.loop(); 43eab5e07bSShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 442745a763SShuo Chen} 45