Win32 API进行程序设计具有很多优点:应用程序执行代码小,运行效率高,但是他要求程序员编写的代码较多,且需要管理所有系统提供给程序的资源,要求程序员对Windows系统内核有一定的了解,会占用程序员很多时间对系统资源进行管理,因而程序员的工作效率降低。

 

简单实例

 1 #include <iostream>
 2 #include <windows.h>
 3 using namespace std;
 4 
 5 DWORD WINAPI ThreadProc1(LPVOID lpParameter)
 6 {
 7 
 8     for (int i = 0; i < 10; i++)
 9     {
10         cout << "我是子线程1" << "  " << i << endl;
11     }
12     return 0;
13 }
14 
15 DWORD WINAPI ThreadProc2(LPVOID lpParameter)
16 {
17     cout << "我是子线程2" << endl;
18     return 0;
19 }
20 
21 void main()
22 {
23     HANDLE hThread1,hThread2;
24     hThread1 = CreateThread(NULL, NULL, ThreadProc1, NULL, NULL, NULL);
25     hThread2 = CreateThread(NULL, NULL, ThreadProc2, NULL, NULL, NULL);
26     WaitForSingleObject(hThread1, INFINITE);  //同步
27     WaitForSingleObject(hThread2, INFINITE);
28     cout << "我是主线程" << endl;
29     while (1);
30 }
View Code

相关文章:

  • 2021-11-08
  • 2022-12-23
  • 2021-05-08
  • 2021-12-09
  • 2021-07-07
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
相关资源
相似解决方案