test5.cc revision a1bde736
1a1bde736SShuo Chen#include "EventLoop.h"
2a1bde736SShuo Chen#include <stdio.h>
3a1bde736SShuo Chen
4a1bde736SShuo Chenmuduo::EventLoop* g_loop;
5a1bde736SShuo Chenint g_flag = 0;
6a1bde736SShuo Chen
7a1bde736SShuo Chenvoid run4()
8a1bde736SShuo Chen{
9a1bde736SShuo Chen  printf("run4(): pid = %d, flag = %d\n", getpid(), g_flag);
10a1bde736SShuo Chen  g_loop->quit();
11a1bde736SShuo Chen}
12a1bde736SShuo Chen
13a1bde736SShuo Chenvoid run3()
14a1bde736SShuo Chen{
15a1bde736SShuo Chen  printf("run3(): pid = %d, flag = %d\n", getpid(), g_flag);
16a1bde736SShuo Chen  g_loop->runAfter(3, run4);
17a1bde736SShuo Chen  g_flag = 3;
18a1bde736SShuo Chen}
19a1bde736SShuo Chen
20a1bde736SShuo Chenvoid run2()
21a1bde736SShuo Chen{
22a1bde736SShuo Chen  printf("run2(): pid = %d, flag = %d\n", getpid(), g_flag);
23a1bde736SShuo Chen  g_loop->queueInLoop(run3);
24a1bde736SShuo Chen}
25a1bde736SShuo Chen
26a1bde736SShuo Chenvoid run1()
27a1bde736SShuo Chen{
28a1bde736SShuo Chen  g_flag = 1;
29a1bde736SShuo Chen  printf("run1(): pid = %d, flag = %d\n", getpid(), g_flag);
30a1bde736SShuo Chen  g_loop->runInLoop(run2);
31a1bde736SShuo Chen  g_flag = 2;
32a1bde736SShuo Chen}
33a1bde736SShuo Chen
34a1bde736SShuo Chenint main()
35a1bde736SShuo Chen{
36a1bde736SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
37a1bde736SShuo Chen
38a1bde736SShuo Chen  muduo::EventLoop loop;
39a1bde736SShuo Chen  g_loop = &loop;
40a1bde736SShuo Chen
41a1bde736SShuo Chen  loop.runAfter(2, run1);
42a1bde736SShuo Chen  loop.loop();
43a1bde736SShuo Chen  printf("main(): pid = %d, flag = %d\n", getpid(), g_flag);
44a1bde736SShuo Chen}
45