CPP_多线程

 1 #define _CRT_SECURE_NO_WARNINGS /* VS2013,2015需要这一行 */
 2 #include <stdio.h>
 3 //下载osapi并安装到目录
 4 //本文档为学习文档
 5 #include "osapi/osapi.h"
 6 
 7 // 定义一个类
 8 class Buddhist : public OS_Thread
 9 {
10 private:
11     virtual int Routine()
12     {
13         // 线程体: 执行它的任务
14         for(int i=0; i<100; i++)
15         {
16             printf("ma mi ma mi hong ...\n");
17             OS_Thread::Sleep(1);  //让出秒cpu
18         }
19         return 0;
20     }
21 };
22 
23 class Confucian : public OS_Thread
24 {
25 private:
26     virtual int Routine()
27     {
28         for(int i=0; i<500; i++)
29         {
30             printf("人之初,性本善 ...\n");
31             OS_Thread::Sleep(1);
32         }
33         return 0;
34     }
35 };
36 int main()
37 {
38     Buddhist  task1;
39     task1.Run();
40 
41     Confucian  task2;
42     task2.Run();
43 
44     // 
45     printf("--------- 主线程开始 -------\n");
46     for(int i=0; i<10; i++)
47     {
48         printf("********* \n");
49         OS_Thread::Sleep(1);
50     }
51 
52     getchar();
53 
54     return 0;
55 }

 

posted on 2017-12-14 12:59  Doctor_uee  阅读(122)  评论(0)    收藏  举报

导航