test5.cc revision 65c497a3
165c497a3SShuo Chen#include "EventLoop.h" 265c497a3SShuo Chen#include <stdio.h> 365c497a3SShuo Chen 465c497a3SShuo Chenmuduo::EventLoop* g_loop; 565c497a3SShuo Chenint g_flag = 0; 665c497a3SShuo Chen 765c497a3SShuo Chenvoid run4() 865c497a3SShuo Chen{ 965c497a3SShuo Chen printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag); 1065c497a3SShuo Chen g_loop->quit(); 1165c497a3SShuo Chen} 1265c497a3SShuo Chen 1365c497a3SShuo Chenvoid run3() 1465c497a3SShuo Chen{ 1565c497a3SShuo Chen printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag); 1665c497a3SShuo Chen g_loop->runAfter(3, run4); 1765c497a3SShuo Chen g_flag = 3; 1865c497a3SShuo Chen} 1965c497a3SShuo Chen 2065c497a3SShuo Chenvoid run2() 2165c497a3SShuo Chen{ 2265c497a3SShuo Chen printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag); 2365c497a3SShuo Chen g_loop->queueInLoop(run3); 2465c497a3SShuo Chen} 2565c497a3SShuo Chen 2665c497a3SShuo Chenvoid run1() 2765c497a3SShuo Chen{ 2865c497a3SShuo Chen g_flag = 1; 2965c497a3SShuo Chen printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag); 3065c497a3SShuo Chen g_loop->runInLoop(run2); 3165c497a3SShuo Chen g_flag = 2; 3265c497a3SShuo Chen} 3365c497a3SShuo Chen 3465c497a3SShuo Chenint main() 3565c497a3SShuo Chen{ 3665c497a3SShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 3765c497a3SShuo Chen 3865c497a3SShuo Chen muduo::EventLoop loop; 3965c497a3SShuo Chen g_loop = &loop; 4065c497a3SShuo Chen 4165c497a3SShuo Chen loop.runAfter(2, run1); 4265c497a3SShuo Chen loop.loop(); 4365c497a3SShuo Chen printf("main(): pid = %d, flag = %d\n", getpid(), g_flag); 4465c497a3SShuo Chen} 45